I'm making a script that when a player presses a button, a Frame with the same name will turn green. It hasn't worked. Here's what I tried:
script.Parent.MouseButton1Click:Connect(function(click) script.Parent.Parent.PlayerStats[click].BackgroundColor3 = Color3.fromRGB(0, 255, 0) game.ReplicatedStorage.Values.PlayersReady.Value = game.ReplicatedStorage.Values.PlayersReady.Value +1 script.Parent.Visible = false end)
Please help! Thanks!
-JBennettChief9!
Hey!
Since you are always going to be handling any user input on the client (LocalScript), we can use Players.LocalPlayer
to find the local player, and in this situation, the player clicking the button. An example of this is shown below...
local Player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.PlayerStats[Player].BackgroundColor3 = Color3.fromRGB(0, 255, 0) game.ReplicatedStorage.Values.PlayersReady.Value = game.ReplicatedStorage.Values.PlayersReady.Value +1 script.Parent.Visible = false end)
A tip for people that are relatively new: you can't use LocalPlayer
on the server. This is because, well, code that runs on the server is ran on the server, and code that's ran on the client is ran on the client (your computer).
Hope this helped! If it did, please remember to upvote and mark as answered.