Button does not work (Multiplayer)

Godot Version

Godot Engine v4.2.2.stable.official.15073afe3 - https://godotengine.org

Question

I’m new to local multiplayer programming ( I don’t understand anything ). I have a button on my stage and only the first player to click on it can click on it later! The other players can see it when it should appear but can’t click on it.

Can you show the scene? Your description is kind of confusing to read. What exactly do you want to achieve?

Users take turns (Russian roulette)

you can use a method like this:

@rpc("any_peer", "call_local")
func next_player(player_name):
    if name == player_name:
        button.disabled = false
    else:
        button.disabled = true

Then one of the players has to call this method with next_player.rpc(name)

I’ve already done this, the button disable works, but player 2 can’t press it if player 1 has pressed it and vice versa.

You have to pass the name of the player whos next turn it is as an argument, not the one that clicked it

Dude, thank you so much, you don’t know how much time I have on this.

1 Like

Sorry to come back to you, but the buton only works for the one who now hosts. While I didn’t modify anything and it worked, the only thing I did was copy bits of the scene to paste them into another one.

Can you show the code how you determine who is the next player?

func _ready():
	
	player_name = multiplayer.get_unique_id()
	if multiplayer.is_server():
		roulette = randi_range(1, 6)
		starter = randi_range(0, 1)
		animation_roulette.play("Load")
		await animation_roulette.animation_finished
		if starter == 0:
			starter_animation.rpc("Randome2")
			animation_gun.play("Randome1")
		else:
			starter_animation.rpc("Randome1")
			animation_gun.play("Randome2")

func my_turn():
	if multiplayer.get_unique_id() == player_name:
		shoot_button.disabled = false
		if reload > 0:
			reload_button.disabled = false
		timer.start()
		time_left_label.visible = true
		turn = false

Function “my_turn” is called in some animation

I know my code is crap but it worked so far

I set a timer for the maximum time of each player’s turn, at the end of the timer it shoots automatically, and the whole thing works completely, the scene is well synchronized. I don’t understand why the client device can’t click on this particular button (shoot and reload), because the quit and start again buttons work.

My bad, sorry, it was just a bad animation synchronization, a node was blocking the mouse.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.