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

Custom Sword Not Working? Isn't playing animation and doesn't deal damage.

Server Script:

--[ Variables
local Tool = script.Parent
local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
local Remote = script.Parent.Remote
local Swinging = false
local SwingAnim = "http://www.roblox.com/Asset?ID=1450972333"
local Char = Player.Character or Player.CharacterAdded:Wait()
local Hum = Char:WaitForChild("Humanoid")
local CanDamage = true

--[ Functions
function Hit(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Name == "Core" then
			if hit.Parent.Parent.TeamColor.Value ~= Player.TeamColor then
				if Swinging then
					hit.Parent.Humanoid:TakeDamage(script.Parent.Configurations.SwingDamage.Value)
					CanDamage = false
					wait(1)
					CanDamage = true
				elseif not Swinging then
					hit.Parent.Humanoid:TakeDamage(script.Parent.Configurations.NoSwingDamage.Value)
					CanDamage = false
					wait(1)
					CanDamage = true
				end			
			end
		elseif game.Players:GetPlayerFromCharacter(hit.Parent) then
			if Swinging then
				hit.Parent.Humanoid:TakeDamage(script.Parent.Configurations.SwingDamage.Value)
				CanDamage = false
				wait(1)
				CanDamage = true
			else
				hit.Parent.Humanoid:TakeDamage(script.Parent.Configurations.NoSwingDamage.Value)
				CanDamage = false
				wait(1)
				CanDamage = true
			end
		end
	end
end

function Swing()
	Swinging = true
	local Anim = Instance.new("Animation")
	Anim.AnimationId = SwingAnim
	local AnimTrack = Hum:LoadAnimation(Anim)
	AnimTrack:Play()
	wait(1.2)
	Swinging = false
end

Remote.OnServerEvent:Connect(function(p,key,k)
	if key == "Swing" then
		Swing()
	end
	if key == "Hit" then
		Hit(k)
	end
end)

local script:

--[ Variables
local Player = game.Players.LocalPlayer
local Tool = script.Parent
local Remote = script.Parent.Remote

Tool.Activated:Connect(function()
	Remote:FireServer("Swing")
end)

Tool.Handle.Touched:Connect(function(h)
	Remote:FireServer("Hit",h)
end)

1 comment

0

sadly the same thing is happening to me

1 answer

For one, animations are called from local script. You don't have to use a remote event for that. For number two, their is no part in the Roblox character called 'core'. It's called 'HumanoidRootPart'. Use that instead.

2 comments

0

The core is a part in the game that players have to destroy

0

Is the sword able to damage players? Does that work?

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