Change Time Help

how do i make when a player touch a part the only player that touch the part will change time not other players that did not touch it

Script:

script.Parent.Touched:Connect(function(hit)
	game.Lighting.ClockTime = 1
end)

Basically make it a local script or set it’s runcontext to client so it only affects the clients machine and doesn’t touch the servers state

You should read more about the server and client replication of Roblox.
You can do that here.

Any changes done on the server will be automatically replicated to all other clients.
If your property changes across all clients you are using a “server” script. A local script will only execute code on the client side and will not replicate anything to other people.
You can also watching this useful tutorial by ByteBlox to understand it a little bit better.
Simply change your script to a local one and it will work. That’s the whole solution.

1 Like

If that’s a script in the workspace, simply changing it to local won’t work, since LocalScripts don’t work in the workspace. You’d need to use a RemoteEvent.

--Script under the part
script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        game.ReplicatedStorage.RemoteEvent:FireClient(player)
    end
end)

and:

--LocalScript under StarterPlayerScripts
local rStorage = game:GetService("ReplicatedStorage")
local event = rStorage:WaitForChild("RemoteEvent")

event.OnClientEvent:Connect(function()
    --time code here
end)

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