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

How to move a local script into the player with a server script?

Asked by 3 years ago

I'm trying to move a local script into the player at a certain point so I can detect player input, and move said local script out after once a certain condition is met. However for whatever reason I the code cannot even find "PlayerScripts" inside the player.

ProximityPrompt.Triggered:Connect(function(plr)
    Seat:Sit(plr.Character.Humanoid)
    player = plr
    local ClientSideScript = Vehicle.ClientVehicleScript:Clone()
    ClientSideScript.Parent = plr.PlayerScripts
    Seat.ProximityPrompt.Enabled = false 
end)

Based on the nature of this issue I thought it has something to do with filtering enabled and all that jazz with not being able to edit things from the client. However, this whole code is running from a server script so I have no clue why I would be getting the error " PlayerScripts is not a valid member of Player"

1 answer

Log in to vote
0
Answered by 3 years ago

Player scripts cannot be seen from the server. You can see this for yourself by going into Roblox Studio and testing server sided, then going into your player object. You will see that there is no player scripts folder.

There is another way you can do this, if you set up a remote event and fire the client from this proximity trigger, you can make a local script inside of the player scripts to run.

Ex:

-----SERVER SCRIPT---------
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

ProximityPrompt.Triggered:Connect(function(plr)
    Seat:Sit(plr.Character.Humanoid)
    Seat.ProximityPromptEnabled = false
       event:FireClient(plr, Vehicle)
end)


-----CLIENT SCRIPT---------

local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local players = game:GetService('Players')
local player = players.LocalPlayer

event.OnClientEvent:Connect(function(vehicle)
    local ClientSideScript = Vehicle.ClientVehicleScript:Clone()
    ClientSideScript.Parent = player.PlayerScripts
end)

I have not tested this code yet, but it should work. If not I think you get the general idea of it. Fire the client from the server and the client runs the code instead.

0
Well, problem is, I need to run the code on the server side. However now that you mention it, I could probably use remote functions called from the client. generalYURASKO 144 — 3y
Ad

Answer this question