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:
1 | local Players = game:GetService( "Players" ) |
2 | local Player = Players.LocalPlayer |
3 |
4 | script.Parent.MouseButton 1 Click:Connect( function () |
5 | script.Parent.Parent.PlayerStats [ Player.Name ] .BackgroundColor 3 = Color 3. fromRGB( 0 , 255 , 0 ) |
6 | game.ReplicatedStorage.Values.PlayersReady.Value = game.ReplicatedStorage.Values.PlayersReady.Value + 1 |
7 | script.Parent.Visible = false |
8 | 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.
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?
1 | local Players = game:GetService( "Players" ) |
2 |
3 | Players.PlayerAdded:Connect( function ( Player ) |
4 | script.Parent.Parent.PlayerStats [ Player.Name ] .BackgroundColor 3 = Color 3. fromRGB( 0 , 255 , 0 ) |
5 | game.ReplicatedStorage.Values.PlayersReady.Value = game.ReplicatedStorage.Values.PlayersReady.Value + 1 |
6 | script.Parent.Visible = false |
7 | 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.
You can use a ClickDetector for your script.
1 | local clickDetector = Instance.new( 'ClickDetector' , script.Parent); |
2 |
3 | clickDetector.MouseClick:connect( function (player) |
4 | --what you want to happen |
5 | end ) |
Also, I'm pretty sure that you can't do local Player = Players.LocalPlayer
if it's not in a local script.