Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script connected to remote event cannot locate player scripts?

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!

4 comments

0

Try debugging it, loop through P and find everything. Scripts do have access to PlayerScripts I am not sure, I will be trying to reproduce this and tell you if I find a solution.

0

Wait why do you need a RemoteEvent for this in the first place? You can just disable it in the Local Script.

0

I'm trying to make a sort of Admin GUI where I can disable any player's movement by typing in their name, clicking a button and it will disable their movement, its for a horror style game im making for me and some friends and I want to be able to trap them in place.

0

If that's the case I suggest you anchor their HumanoidRootPart, use a BodyPosition or there are many other ways to freeze them. I can't seem to find PlayerScripts either.

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.