Help with boolean value

Hi, i want to make an axe and a tree. When i am touched a tree with axe, script will check is axe swinging.But when i add a bool value in a axe and change it with a script it didn’t work

What is the issue?

--change bool value 
function Activated() --when you swing
	if Tool.Enabled then
		
		Tool.Enabled = false 
		script.Parent.IsSwing.Value = true
		Whack = Humanoid:LoadAnimation(WhackAnim)
		if Whack then
			Whack:Play()
			SlashSound:Play()
		end
		wait(ReloadTime)
		script.Parent.IsSwing.Value = false
		Tool.Enabled = true
	end
end

---------------------------------------------------------
---check swing script

script.Parent.Touched:Connect(function(hit)
	local tool = hit.Parent
	
	if tool:FindFirstChild("IsAxe")  then
	
		if tool.IsSwing == true then
			game.Workspace.sound1:Play()
				
				print("test")
                        end
        end
end)

Thank you for reading.

1 Like

Change that line to this:

tool.IsSwing.Value == true

still it doesn’t print anything

maybe add print() in lines

just for checking which lines isn’t true so you can continue to check your whole scripts

It doesn’t print anything after

if tool.IsSwing.Value == true then

maybe can i see your tool’s children?

maybe you can print(tool.IsSwing.Value)

script.Parent.Touched:Connect(function(hit)
	local tool = hit.Parent

print(1)
	
	if tool:FindFirstChild("IsAxe")  then
    print(2)
    print(tool.IsSwing.Value)

		if tool.IsSwing.Value  == true then
			game.Workspace.sound1:Play()
				
				print("test")
                        end
        end
end)
1 Like

these are tool’s children

1 Like

it prints “false”
but in properties it shows true

did you set your

IsSwing.Value in localscript?
try to set its value in script instead of localscript

1 Like

Instead of doing that, do this:

 tool.IsSwing.Changed:Connect(function()
 if tool.IsSwing.Value == true then
 -- do stuff -- 
 end
 end)
1 Like

where should i put localscript

Okay i understand. I put change value codes in a localscript. so it doesn’t change anything in server-side

Thanks everyone!

> Client = Player
> Server = Host

Ok, so you used client to make boolean val = true but server still sees it’s false because you didn’t set your boolean val with server script to make the server sees it’s true you need to move your boolean val = true into server script instead of localscripta ones to make server sees that your value is now true, not false.

most localscripts are used with UIs

don't trust client

1 Like