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

Is .Touched Event broken or did I do something wrong? Need help!

Asked by 6 years ago

Here's my script;

local Sword = script.Parent
local Hitting = false
local Dmg = script.Parent.Parent:WaitForChild('Stats').Damage

Sword.Touched:Connect(function(hit)
    print('TOUCHED THE GOD')
    if hit.Parent:FindFirstChild('Humanoid') then
        if Hitting == false then
            Hitting = true
            if Hitting == true then
                return
            else
                local Enemy = hit.Parent:FindFirstChild('Humanoid')
                Enemy.Health = Enemy.Health - Dmg.Value
                wait(2)
                Hitting = false
            end
        end
    end
end)

This is a Server Script inside of a part inside of a model.

Stats is a folder inside the model.

Inside stats we have the stats (duh) they are number values.

I'm not sure if I did something wrong but It's not doing damage.

Thank you for any feed back support and help.

0
You should use GetPlayerFromCharacter(hit) PyccknnXakep 1225 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I don't think there is any reason to use the hitting variable, but I think you needed to add GetPlayerFromCharacter, because thehit.Parent would just be the player, and the humanoid is located inside of the players character.

local Dmg = script.Dmg
script.Parent.Touched:Connect(function(hit) 
    local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
    local hum = player.Character.Humanoid
    hum.Health = hum.Health - Dmg.Value
    end)

Hopefully this works for you. If it did, please upvote and accept answer. If it didn't please comment. Thanks!

0
No. The humanoid is located on the player's module under Workspace, not the service, Players. hiimgoodpack 2009 — 6y
0
Oh. I see. PyccknnXakep 1225 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I think this is what is broken. On line 10, why did you make a if statement if that value just got immediately changed? That is why it is not working.

0
Hold on I will keep this note right here. I'm currently working on something else I will come back after fixing. BlackOrange3343 2676 — 6y

Answer this question