Stop normal scripts in workspace from running locally while playing/playtesting

I have a cable car system where someone would talk to an npc. Doing that would trigger the geartiminghandler sccript which reverses the conveyor direction, waits X seconds, then reverses it again. further detail is in the video.
when i run the game, everything works fine. the scripts have that green server icon as intended and the cable car moves just fine (normally it would go all the way down and then wait, but for testing purposes i shortened it to a few seconds). the cables are conveyors that push the cable car up and down, and they are handled by another script.
when i play the game however, (from what i believe) they run locally because of the pc icon. How do i prevent this? how do i make then function just like when i run the game? i also tried testing it on roblox but its the same as playtesting.
i tried setting runcontext to server but nothing happened. I searched other posts similar but none seem to have this issue. What can i do, what do i need to add or remove from the script?
I really don’t know almost anything about this server-client stuff so any help is appreciated

video of the issue: https://www.youtube.com/watch?v=1vLtgNRf018

When you hit run, you are viewing Explorer from the context of the server.
However, when you hit play, you are viewing the Explorer from the context of the client.
This means that any changes you make to objects in the game through explorer (such as setting the enabled state of the script) are done on the client side and not the server side, which can cause things to not work how you intended (like in your case).

If you want to change to the server context while playing, hit the button in the image below to change!
image

2 Likes

You would have to use a RemoteEvent that fires to the server wheenver the user wants the cart to start. Since enabling it locally wouldn’t do anything because it doesn’t replicate to the server.

oh.. thanks, i dont think i would have ever figured that out, not anytime soon at least.. but for the second part, this is activated from a localscript inside the npc that the player talks to. From that local script, there’s this phrase which is supposed to activate the geartiminghandler script

game.Workspace.System1.geartiminghanler.Enabled = true

but now i know that it activates it only locally, is there a way to make that script activate server side/globally? i dont really know if localscripts can do that, or if i have to use a RemoteEvent or something

You can use a RemoteEvent and fire it on the client, on the server-side you want to use the RemoteEvent’s OnServerEvent property. It could look something like this:

Client:

local event = ReplicatedStorage.RemoteEvent --Event that triggers the handler
event:FireServer()

Server:

local event = ReplicatedStorage.RemoteEvent

event.OnServerEvent:Connect(function()
--Server will run this script if a client fires the event
end)

This is only a very rough example

The event will also give the Player who fired the event as a first parameter by default, but you can add additional parameters by putting them into the :FireServer():

event:FireServer("Hi")
event.OnServerEvent:Connect(function(PlayerWhoFired,message)

end)

As Fietowski said, you would need to utilise remote events, which allows the client to ask the server to do something (and vice versa)

You can find the documentation for remote events below:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.