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

Sword damage script not working in a real game?

Asked by 6 years ago
Edited 6 years ago
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local flesh = handle:WaitForChild("Hit")
local blade = tool:WaitForChild("Blade")
local detect = tool:WaitForChild("CanAttack")

blade.Touched:connect(function(hit)
    if detect.Value == true then
        local hum = hit.Parent:FindFirstChild("NPC")
        if hum then
--[[        
            for i,v in pairs(hit.Parent:GetChildren()) do
                if v:IsA("IntValue") then
                    v:Destroy()
                end
            end
            local kill = Instance.new("IntValue",hit.Parent)
            kill.Name = script.Parent.Parent.Name
--]]
            detect.Value = false
            flesh:Play()
            hum:TakeDamage(4)
            wait(1)
            detect.Value = true
        end
    end
end)

When the blade of the sword (a part) hits a NPC, it will check for the NPC's humanoid which is named "NPC" so that players can't kill each other. If it finds it, it will do damage to the NPC. The script works in studio but not in a real game with no errors.

0
Try putting it into a localscript instead of a normal script. Galicate 106 — 6y
0
Didn't work. InfernoExeuctioner 126 — 6y

Answer this question