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

Why does my tool not change a value within a part after colliding with it?

Asked by 3 years ago
Edited 3 years ago

So basically i have an axe and a tree with a NumberValue that's name is "Health" and when I slash with the axe and the head of the axe collides with the tree its supposed to do 5 dmg but it doesn't even detect the number value

script:

Properties = {
    debounce = true, -- Leave this on true.
    sound_fx = true, -- If you don't want sound to play when tool is activated set this to false.
    anim_check = true, -- If you don't want animation to play when tool is activated set this to false.
    ToolDrop = false, -- Set this to true if you want to be able to drop the tool by pressing BackSpace.
    soundID = 6042531284, -- Sound Id.
    AnimID = 6461572129, -- Your Animtion id.
    debounce_lenght = 1, -- how long it will take before you can click again, aka cooldown so you can't spam click the tool.
    soundDelay = 0.25, -- How long to wait before playing sound
    enableTrail = true, -- Enable trail thing
    trail = script.Parent.Head.Trail, -- the trail thing
    damage = 5 -- how much dmg the thing does
}

local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local BaseUrl = "rbxassetid://"
local anim = Tool:WaitForChild("Animation")
local Players = game:GetService("Players")


if Properties.sound_fx then 
    sound = Handle:WaitForChild("Sound")
    sound.SoundId = BaseUrl .. Properties.soundID
    sound.MaxDistance = 100
    sound.RollOffMode = Enum.RollOffMode.InverseTapered
end



if Properties.anim_check then   
    anim.AnimationId = BaseUrl .. Properties.AnimID
end


if Properties.ToolDrop == true then
    Tool.CanBeDropped = true
end

Tool.Equipped:Connect(function(Mouse) -- When you equip the tool
    local player = Players:GetPlayerFromCharacter(Tool.Parent) -- gets the player
    if Properties.anim_check == true then animation = player.Character.Humanoid:LoadAnimation(anim)end -- loads animation

    Tool.Activated:Connect(function() -- when you click with the tool
        if Properties.debounce then
            Properties.debounce = false
            if Properties.anim_check == true then animation:Play()end
            if Properties.sound_fx == true then wait(Properties.soundDelay) sound:Play()end

            if Properties.enableTrail == true then
                Properties.trail.Enabled = true
                wait(0.2)
                Properties.trail.Enabled = false
            end

            script.Parent.Head.Touched:Connect(function(Hit)
                print(Hit.Name)
                if Hit:FindFirstChild("NumberValue") and Hit:FindFirstChild("NumberValue").Name == "Health" then
                    local temp = Hit:FindFirstChild("NumberValue")
                    print(temp.Name .. ": " .. temp.Value)
                    temp.Value = temp.Value - Properties.damage
                end
            end)

            wait(Properties.debounce_lenght)    
            Properties.debounce = true
        end 
    end)
end)
Tool.Unequipped:Connect(function()
    if Properties.anim_check == true then animation:Stop()end
    if Properties.sound_fx then sound:Stop()end
end)
0
LocalScript or ServerScript? OhManXDXD 445 — 3y
0
Also is the name of the NumberValue “NumberValue”? OhManXDXD 445 — 3y
0
Server script and read the description EiOooAxea 70 — 3y

1 answer

Log in to vote
1
Answered by
OhManXDXD 445 Moderation Voter
3 years ago

I think the problem here is, you are looking for a child named “NumberValue” but not a NumberValue itself.

Use FindFirstChildWhichIsA() to find a type of child instead of the name of a child


Properties = { debounce = true, -- Leave this on true. sound_fx = true, -- If you don't want sound to play when tool is activated set this to false. anim_check = true, -- If you don't want animation to play when tool is activated set this to false. ToolDrop = false, -- Set this to true if you want to be able to drop the tool by pressing BackSpace. soundID = 6042531284, -- Sound Id. AnimID = 6461572129, -- Your Animtion id. debounce_lenght = 1, -- how long it will take before you can click again, aka cooldown so you can't spam click the tool. soundDelay = 0.25, -- How long to wait before playing sound enableTrail = true, -- Enable trail thing trail = script.Parent.Head.Trail, -- the trail thing damage = 5 -- how much dmg the thing does } local Tool = script.Parent local Handle = Tool:WaitForChild("Handle") local BaseUrl = "rbxassetid://" local anim = Tool:WaitForChild("Animation") local Players = game:GetService("Players") if Properties.sound_fx then sound = Handle:WaitForChild("Sound") sound.SoundId = BaseUrl .. Properties.soundID sound.MaxDistance = 100 sound.RollOffMode = Enum.RollOffMode.InverseTapered end if Properties.anim_check then anim.AnimationId = BaseUrl .. Properties.AnimID end if Properties.ToolDrop == true then Tool.CanBeDropped = true end Tool.Equipped:Connect(function(Mouse) -- When you equip the tool local player = Players:GetPlayerFromCharacter(Tool.Parent) -- gets the player if Properties.anim_check == true then animation = player.Character.Humanoid:LoadAnimation(anim)end -- loads animation Tool.Activated:Connect(function() -- when you click with the tool if Properties.debounce then Properties.debounce = false if Properties.anim_check == true then animation:Play()end if Properties.sound_fx == true then wait(Properties.soundDelay) sound:Play()end if Properties.enableTrail == true then Properties.trail.Enabled = true wait(0.2) Properties.trail.Enabled = false end script.Parent.Head.Touched:Connect(function(Hit) print(Hit.Name) if Hit:FindFirstChildWhichIsA("NumberValue") and Hit:FindFirstChildWhichIsA("NumberValue").Name == "Health" then local temp = Hit:FindFirstChildWhichIsA("NumberValue") print(temp.Name .. ": " .. temp.Value) temp.Value = temp.Value - Properties.damage end end) wait(Properties.debounce_lenght) Properties.debounce = true end end) end) Tool.Unequipped:Connect(function() if Properties.anim_check == true then animation:Stop()end if Properties.sound_fx then sound:Stop()end end)
0
Ty it works now, i just gotta add a de bounce system to it somehow,im not super familiar with how to make a debounce system so any help is appreciated EiOooAxea 70 — 3y
0
It looks like there is already a debounce implemented OhManXDXD 445 — 3y
0
there isnt? EiOooAxea 70 — 3y
0
Properties.debounce OhManXDXD 445 — 3y
View all comments (7 more)
0
wait nvm thats for the animation etc but i need to de bounce the damage etc EiOooAxea 70 — 3y
0
i added a simple debounce but it didnt seem to work for whatever reason EiOooAxea 70 — 3y
0
it does the damage 2 times EiOooAxea 70 — 3y
0
sometimes it does once, sometimes twice and sometimes 3 times EiOooAxea 70 — 3y
0
nvm i fixed the debounce somehow lol EiOooAxea 70 — 3y
0
nvm i fixed the debounce somehow lol EiOooAxea 70 — 3y
Ad

Answer this question