Why isn't this working? (True/False value)

Hey there,

I’m new to scripting and I’m sure the issue is small but I’m not seeing any Errors in output

Problem: The local script isn’t changing the value to False when clicked.

Local Script:

local onoff = game.StarterGui.DisableBlood.OnOff.Value

local toggle = script.Parent.Frame.Toggle

toggle.MouseButton1Down:Connect(function()

onoff = false print(onoff)

end)

Script:

  hurt = true	 -- Damage
  for _, child in pairs(wep:GetChildren()) do
  	if child:IsA("Part") then	
  	child.Touched:connect(function(hit)
  		if hit.Parent:FindFirstChild("Humanoid") ~= nil and hurt == true then
  			soundsclone.Hit:Play()
  			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
  			hurt = false
  			if onoff == true then print(onoff)
  			Bleed:FireAllClients(hit)
  			end
  			elseif onoff == false then
  			end

Thank you,

Is that the whole script? Because your not telling it when to run.

This is a common mistake that I see almost everyday on here. Don’t refer to instances inside StarterGui unless you’re specifically referring to those instances.

Think of StarterGui as a container that the Server uses to hold all the GUI objects that should be replicated to the player. Each player has a PlayerGui. This is where the Server replicates the instances of StarterGui to.

local player = game.Players.LocalPlayer
local onoff = player.PlayerGui.DisableBlood.OnOff

local toggle = script.Parent.Frame.Toggle

toggle.MouseButton1Down:Connect(function()

    onoff.Value = false 
    print(onoff)

end)

Another thing, in your original code, the variable onoff is initialized with the value of DisableBlood. You want to instead store the reference to the DisableBlood BooleanValue instance. From there, you can reassign the value of DisableBlood by using .Value. Your current approach will only change the value of the variable inside your script.

1 Like

Thanks for that info, So i should move the Value (OnOff) elsewhere? that can be accessed via the Local script?

It can be accessed by the local script already. See the example code I’ve written.

You can also place inside StarterPlayer and it should replicate inside the Player object itself. Either way works.

I’ve applied your changes and it does update the Value to false but still fires the Event as if it were True

That might be an issue with your server side script. Since this variable is local, the toggling would only take place locally.

You might want to consider restructuring this system. Perhaps have the server store a table of all players with their bleed preferences and have the client fire to the server whenever the player presses the toggle button.