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

How do you change a BoolValue from a local script?

Asked by 4 years ago

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

1 answer

Log in to vote
1
Answered by 4 years ago

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.

0
Thanks! Hederlunden 19 — 4y
Ad

Answer this question