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

A Script for a sword in fighting game not working!?

So i have a sword and in the sword is a script and a local script local words but the server script doesn't I need help heres the code I never scripted a weapon(I scripted a few tools before but not a weapon) so it might be bad

local tool = script.Parent

local char = tool.Parent

local mindmg = 15

local maxdmg = 70

tool.Activated:Connect(function()
	tool.blade.Touched:Connect(function(p)
		local hitted = game.Players:GetPlayerFromCharacter(p.Parent)
		local hitter = game.Players:GetPlayerFromCharacter(char)
		if hitted and hitter then
			if hitted.TeamColor == hitter.TeamColor then
			else
		p.Parent.Humanoid:TakeDamage(math.random(mindmg,maxdmg))
		end
	end
end)
end)

3 comments

0

is this a local script

0

Where are you defining him at line 11?

0

so i had hum but i changed to p for whatever reason sorry

1 answer

Touched Events require an argument as the part hit, therefore line 11 of where you said hum.Parent isn't actually the player you hit.

local tool = script.Parent

local char = tool.Parent

local mindmg = 15

local maxdmg = 70

tool.Activated:Connect(function()
    tool.blade.Touched:Connect(function(p)
	--Need to change hitted to the actual character which was hit.
        local hitted = game.Players:GetPlayerFromCharacter(p.Parent)
        local hitter = game.Players:GetPlayerFromCharacter(char)
        if hitted and hitter then
            if hitted.TeamColor == hitter.TeamColor then
            else
        p.Parent.Humanoid:TakeDamage(math.random(mindmg,maxdmg))
        end
    end
end)
end)

1 comment

0

I once used hum and changed it sorry

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