Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Need help with remote functions, what did I do wrong?

Hey, I have problem with my remote function.

This is how it should work: When a player press a button in the gui on the screen a red frame will appear for all players on that button. This is so it's not possible to press the button for the other players but also the player that pressed the button.

Nothing happens when I press the button, I only get this warning "Infinite yield possible on 'ReplicatedStorage:WaitForChild("BalancingTileRed")'"

Does anyone know what is wrong with my script?

ServerScript

local rs = game:GetService("ReplicatedStorage")
local BalancingTileRed = rs:WaitForChild("BalancingTileRed")

local function balancingTileRed(player)
	
	if rs.ChooseNextGame.BalancingTile == "Balancing Tile" then
		script.Parent.Visible = true
		script.Parent.Parent.Visible = false
	end
	
end

BalancingTileRed.OnServerInvoke = balancingTileRed

LocalScript

local rs = game:GetService("ReplicatedStorage")
local BalancingTileRed = rs.Remotes:WaitForChild("BalancingTileRed")

local changeToRed = BalancingTileRed:InvokeServer()

Thanks for the help, Xsodar

2 answers

Change line 2 of the server script to:

local BalancingTileRed = rs.Remotes:WaitForChild("BalancingTileRed")

The script was waiting for a BalancingTileRed in ReplicatedStorage when it should've been looking for it in ReplicatedStorage.Remotes.

local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

button.MouseButton1Click:Connect(function()
	remoteEvent:FireServer()
end

remoteEvent.OnClientEvent:Connect(function()
	--make red frame appear
end

--server

local remoteEvent = game.ReplicatedStorage.RemoteEvent

local table = {} --i recommend you checking if the player can press the button or not on the server. you can do this by adding them to a table whenever the button is press

remoteEvent.OnServerEvent:Connect(function(player)
	if not table[player.UserId] then  --check if player is in table
		table[player.UserId] = player --if not, add them to the table
		remoteEvent:FireAllClients()  --and fire client event for all players
		for _,plr in pairs (game.Players:GetPlayers()) --returns table of players
			if not table[plr.UserId] then 
				table[plr.UserId] = plr  
			end
		end
	end 
end

table[player.UserId] = nil --removes a specific player from the table
table = {} --clears the entire table

Let me know if you have any issues.

3 comments

0

Thank you, that removed my warning, but nothing happens when I click the button, do you know why? Or is it another way I can send value from 1 client to all the other one?

0

I honestly don't know how to work with remote functions but I think your desired results can be accomplished with remote events. I'll edit my answer rq

0

i assume it's because of;; if rs.ChooseNextGame.BalancingTile;; you probably forgot [.Value], should be;; if rs.ChooseNextGame.BalancingTile.Value;; Also why'd you use remote function for UI updates

If you have an error for the red screen not showing up. Then one thing I can suggest is instead of using StarterGui. Try using the PlayerGui. So it'd be like:

RemoteEvent.OnServerEvent:Connect(function(player)

player.PlayerGui.YourFrameHere.Visible = true

This discussion is preserved as it was. New answers, comments, and votes are closed.