Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script connected to remote event cannot locate player scripts?

Asked by 5 years ago

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!

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. sweettart13947 105 — 5y
0
Wait why do you need a RemoteEvent for this in the first place? You can just disable it in the Local Script. sweettart13947 105 — 5y
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. kindacoolguy4000 2 — 5y
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. sweettart13947 105 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
Ad

Answer this question