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

How do I define a script with a RemoteEvent?

Ok... I know I asked this before... but I haven't figured it out yet so I need some help. When the TextButton is clicked, I need to find the name of the player who clicked the Button, then a Frame with the player's name will turn green. Here's the code I tried:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.PlayerStats[Player.Name].BackgroundColor3 = Color3.fromRGB(0, 255, 0)
    game.ReplicatedStorage.Values.PlayersReady.Value = game.ReplicatedStorage.Values.PlayersReady.Value +1
    script.Parent.Visible = false
end)

This is not a LocalScript and it is not working. Do I need to use some kind of RemoteEvent? Could use some help. Thanks.

3 answers

You do game.Players.LocalPlayer or access the LocalPlayer using that in any way in a server script, you need to use a local script. Also, do you want the frame to show for everyone in the server or just the local player?

7 comments

0

For everybody

0

You won't need a remote event if you use a player added event with the parameter of player/plr and then get the mouse button click, then make the GUI visible and use player.Name/plr.Name for the player name.

0

...Please just run that Script through with me

0

I can't post another answer

0

Aww

0

put a mouse button click function inside a player added event function and inside the mouse button click function do game.PlayerGui.GUI.Frame.Text = player.Name, and on the next line do game.PlayerGui.GUI.Frame.Visible = true. Make sure to accept this answer if it helped.

0

Nope, Didn't work

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function( Player )
	script.Parent.Parent.PlayerStats[Player.Name].BackgroundColor3 = Color3.fromRGB(0, 255,0)
	game.ReplicatedStorage.Values.PlayersReady.Value = game.ReplicatedStorage.Values.PlayersReady.Value +1
	script.Parent.Visible = false
end)

This should fix your issue if you're trying to do it on the server, if you're trying to hook it up to a UI click, you're gonna want to use YOUR code, but use a local script instead.

4 comments

0

PlayerAdded doesn't work on the client.

0

This is a server script. I literally said that in the case of a local script for JB to use his script and not mine.

0

I'll use it in a little bit and see if it works. I will accept the answer if it works. Thanks mate

0

Sorry, didn't work. It's a TextButton and happens when it is clicked

You can use a ClickDetector for your script.

local clickDetector = Instance.new('ClickDetector', script.Parent);

clickDetector.MouseClick:connect(function(player)
	--what you want to happen
end)

Also, I'm pretty sure that you can't do local Player = Players.LocalPlayer if it's not in a local script.

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