I am currently having an issue where i'm trying to disable the player's movement via GUI but when I click the button it can't seem to locate PlayerScripts. Here is the error:
16:42:29.608 - PlayerScripts is not a valid member of Player 16:42:29.609 - Stack Begin 16:42:29.609 - Script 'ServerScriptService.Controlling', Line 6 16:42:29.609 - Stack End
and here is my code:
local script:
script.Parent.MouseButton1Click:Connect(function() local P = game.Players:FindFirstChild(script.Parent.Parent.TextBox.Text) game.ReplicatedStorage.Events.Disable:FireServer(P) end)
server script:
--Disable Movement-- Events.Disable.OnServerEvent:Connect(function(P) local controls = require(P.PlayerScripts.PlayerModule):GetControls() controls:Disable() end)
Thanks, for the help, in advance!
My bad, if you look at https://developer.roblox.com/en-us/api-reference/class/PlayerScripts It say it's not replicated. I have a solution:
You'd put this in StarterPlayerScripts:
--LocalScript local Player = game:GetService("Players").LocalPlayer local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent function UpdateControls(Movement) Movement = Movement and "Enable" or "Disable" local Controls = require(Player.PlayerScripts.PlayerModule):GetControls() Controls[Movement](Controls); end RemoteEvent.OnClientEvent:Connect(UpdateControls)
And I guess get this to work with your script:
--Server local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent function FindTarget(Target) for i,v in next, game:GetService("Players"):GetPlayers() do if v.Name:lower():sub(1,#Target) == Target:lower() then return v end end end function UpdateMovement(Player, Target, Movement) Target = FindTarget(Target) if Target then RemoteEvent:FireClient(Target, Movement) end end RemoteEvent.OnServerEvent:Connect(UpdateMovement)