I am trying to change a BoolValue in ReplicatedStorage from a local script. The value changes, but the server script that I have is not doing anything. Here is a part of the server script:
It's in a while true do loop
elseif game.ReplicatedStorage.ClockTimeValue.Value ~= 6 and game.ReplicatedStorage.Stig.Value == true then game.Lighting.StigForeverJumpScare.Parent = game.Workspace game.ReplicatedStorage.JumpscareTime.Value = true print("time for jumpscare")
Hello. You have to use RemoteEvents
. They are used for client (player) and server communication. First, insert a RemoteEvent
in ReplicatedStorage
and call it "BoolTrueEvent". Now the part of your LocalScript
to this:
elseif game.ReplicatedStorage.ClockTimeValue.Value ~= 6 and game.ReplicatedStorage.Stig.Value == true then game.Lighting.StigForeverJumpScare.Parent = game.Workspace game.ReplicatedStorage.BoolTrueEvent:FireServer() print("time for jumpscare")
This will fire the RemoteEvent
for the server. Now, insert a Script
into ServerScriptService
or Workspace
. Write the following code:
game.ReplicatedStorage:WaitForChild("BoolTrueEvent").OnServerEvent:Connect(function(player) game.ReplicatedStorage.JumpscareTime.Value = true end)
The event will fire whenever the "BoolTrueEvent" fires, which it did in the LocalScript
. Also, you automatically get the player who fired that event as a parameter of the OnServerEvent
event. Please upvote and accept this answer if it helped.