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
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.
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.