Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I define a script with a RemoteEvent?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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?

0
For everybody JB_SuperGamer 165 — 4y
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. Swaggyguy229 7 — 4y
0
...Please just run that Script through with me JB_SuperGamer 165 — 4y
0
I can't post another answer Swaggyguy229 7 — 4y
View all comments (3 more)
0
Aww JB_SuperGamer 165 — 4y
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. Swaggyguy229 7 — 4y
0
Nope, Didn't work JB_SuperGamer 165 — 4y
Ad
Log in to vote
0
Answered by
yellp1 193
4 years ago
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.

0
PlayerAdded doesn't work on the client. youtubemasterWOW 2741 — 4y
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. yellp1 193 — 4y
0
I'll use it in a little bit and see if it works. I will accept the answer if it works. Thanks mate JB_SuperGamer 165 — 4y
0
Sorry, didn't work. It's a TextButton and happens when it is clicked JB_SuperGamer 165 — 4y
Log in to vote
0
Answered by 4 years ago

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.

Answer this question