for some reason, it doesn’t detect the playerscripts when I click it, and instead shows an error that states PlayerScripts is not a valid member of Players.MyName. Does anyone know why this is happening? I’ve made scripts in the past that add a tool to a player’s backpack through a workspace button, so I don’t know what the problem is.
You’re unable to see PlayerScripts, or at least reference it the way you have on the server to my knowledge. Below is what you’d see on your server for the player:
Instead, on MouseClick you can fire to the client, which will allow you to reference PlayerScripts.
You should do what @alphadoggy111 said, have a RemoteEvent with a server script and a local script. The server script fires to the remote event when a player presses the button, and the hooked up local script executes the code to modify PlayerScripts.
local clickPart = workspace:WaitForChild"Part"
local clickDetector = clickPart:WaitForChild"ClickDetector"
local function onClicked(player)
local playerScripts = player:WaitForChild"PlayerScripts"
end
clickDetector.MouseClick:Connect(onClicked)
Local script inside StarterPlayerScripts. No RemoteEvent required.