Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

XP Giver Breaks When Touched by Humanoid? How to Prevent?

I have a script that would give XP whenever a tool touches it. Thing is whenever someone's head or body touches it, it breaks. Is there any way to make it so that only when the tool touches it, it will work, not when a player's head touches it.

XP Giver:

local debounce = false

script.Parent.Touched:connect(function(hit)
    if not debounce then
	    debounce = true
	    local look = hit.Parent:FindFirstChild("BallHandler").Value -- value in basketball
	        local found = game.Players:FindFirstChild(look)
	        local cash = found:FindFirstChild("leaderstats")
	        cash.XP.Value = cash.XP.Value + 5
	        print("Gave +1 SM")
	        wait(1)
	    debounce = false
	end
end)

BallHandler Script:

while wait() do
	plr=game.Players:FindFirstChild(script.Parent.Parent.Parent.Name)
	if plr then
		script.Parent.Value=plr.Name
	end
end

Thanks,

LukeGabrieI aka EnergyBrickz

1 answer

✓ Accepted answer

Create a conditional statement that requires the tool or tool's part to be named a certain name, or the part touched's parent be of a certain class.

For example:

if hit.Name == "ExampleName" or hit.Parent:IsA("Tool") then
	-- do the rest of my code here
end

4 comments

0

would i put this in the part thats going to be touched or inside the tool's handle

1

You would add it inside script.Parent.Touched:connect(function(hit)

0

thank you so much!

1

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.