2 issues with my sword script

I have two issues with my sword script, 1 when the sword’s special ability plays its shock wave continuelsy gets bigger every time the ability is used. Basically the shock wave doesn’t reset to its normal size and keeps growing. The second error is that the normal slash isn’t working, an error message plays: Attempt to connect failed: Passed value is not a function I didn’t know what was wrong with the connection part of the script. Help please ;-;

local wind = Instance.new("Part", game.Workspace)
wind.Shape = "Cylinder"
wind.Size = Vector3.new(0.7,30.1,74.3)
wind.BrickColor = BrickColor.new("Ghost grey")
wind.Anchored = true
wind.CanCollide = false
wind.Transparency = 1
wind.Material = "SmoothPlastic"

local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(
	5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
	
)
local Goals =
	{
		Size = Vector3.new(1,100,100) ;
	}

local flash = TweenService:Create(wind,Info,Goals)
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local Mouse = player:GetMouse()

local character = player.Character 
local humanoid = character:WaitForChild("Humanoid")
local hi = character:WaitForChild("HumanoidRootPart")
local tool = script.Parent
if tool.Equipped then
function swing()
	local swing = Instance.new("Animation")
	swing.AnimationId = "rbxassetid://7193950823"
	
	local wham = humanoid:LoadAnimation(swing)
	wham:Play()
	wait(1)
	local playpos = CFrame.new(hi.Position)

	wind.CFrame = playpos
	local rotate = CFrame.Angles(0, math.rad(0), math.rad(90))
	wind.CFrame = wind.CFrame:ToWorldSpace(rotate)


	flash:Play()
	wind.Transparency = .1
	wait(.2)
	wind.Transparency = .3
	wait(.2)
	wind.Transparency = .6
	wait(.2)
	wind.Transparency = 1

end
end
Mouse.Button2Down:Connect(swing())

if tool.Equipped then
	function swingn()
		local swingn = Instance.new("Animation")
		swingn.AnimationId = "rbxassetid://7118111810"

		local whamn = humanoid:LoadAnimation(swingn)
		whamn:Play()

		local function onTouch(partOther)

			local humanOther = partOther.Parent:FindFirstChild("Humanoid")

			if not humanOther then return end

			if humanOther.Parent == tool then return end

			humanOther:TakeDamage(5)
		end
	end
end

Mouse.Button1Down:Connect(swingn())

Edit: I fixed the second issue, but now it is saying the same thing about the speacial ability!!!

Another Edit: The normal slash doesn’t do damage just tested it. Still need help btw

1 Like

If the Character is not created yet, it will give nil

It is for a function, not for a property.

Better to use Animator and load them out of the function.

Try this:

local wind = Instance.new("Part", workspace)
wind.Shape = "Cylinder"
wind.Size = Vector3.new(0.7,30.1,74.3)
wind.BrickColor = BrickColor.new("Ghost grey")
wind.Anchored = true
wind.CanCollide = false
wind.Transparency = 1
wind.Material = "SmoothPlastic"

local Info = TweenInfo.new(5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)
local flash = game:GetService("TweenService"):Create(wind,Info,{Size = Vector3.new(1,100,100)})

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hi = character:WaitForChild("HumanoidRootPart")
local tool = script.Parent


local swing1 = Instance.new("Animation")
swing1.AnimationId = "rbxassetid://7193950823"
local wham1 = humanoid:WaitForChild("Animator"):LoadAnimation(swing1)

local swingn2 = Instance.new("Animation")
swingn2.AnimationId = "rbxassetid://7118111810"
local whamn2 = humanoid:WaitForChild("Animator"):LoadAnimation(swingn2)

function swingClick2()
	wham1:Play()
	wait(1)
	
	wind.CFrame = CFrame.new(hi.Position)
	local rotate = CFrame.Angles(0, math.rad(0), math.rad(90))
	wind.CFrame = wind.CFrame:ToWorldSpace(rotate)

	flash:Play()
	wind.Transparency = .1
	wait(.2)
	wind.Transparency = .3
	wait(.2)
	wind.Transparency = .6
	wait(.2)
	wind.Transparency = 1

end
function swingnClick1()
	whamn2:Play()

--	local function onTouch(partOther)
--		local humanOther = partOther.Parent:FindFirstChild("Humanoid")
--		if not humanOther then return end
--		if humanOther.Parent == tool then return end
--		humanOther:TakeDamage(5)
--	end
end

local Equipped = false
tool.Equipped:Connect(function()  Equipped = true  end)
tool.Unequipped:Connect(function()  Equipped = false  end)

game:GetService("UserInputService").InputBegan:Connect(function(Input)
	if not Equipped then  return  end
	
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then  swingnClick1()
	elseif Input.UserInputType == Enum.UserInputType.MouseButton2 then  swingClick2()
	end
end)
2 Likes

Alright cool. I read through it and it looks great, I’ll test it out later today.

Edit: No error messages, and the shock wave still keeps getting bigger and the sword doesn’t deal damage.

Remove the double parenthesis. It doesn’t work like that:

Mouse.Button1Down:Connect(swingn) -- this will work

You’re also dealing damage on the client. Use a remote event to signal the server to deal the damage.

Im… not great with using remote events. I mean I don’t know the code to make a remote event work… And if you explain it could you go off of @SOTR654’s script? I looked through it and it works better than my script.

You can reference my post that I made a while back. Remote events communicate between the client and the server, server, and the clients, etc.

function swingnClick1()
	whamn2:Play()
	remote:FireServer()
		local function onTouch(partOther)
			local humanOther = partOther.Parent:FindFirstChild("Humanoid")
		if not humanOther then return end
		if humanOther.Parent == tool then return end
			humanOther:TakeDamage(30)
		end
	
end

Remote was already defined to my remote event. I doubt I’m using remote events correctly… But it doesn’t work.

The script could be one from the server with some changes, but Activated is not activated by right click, as @benpinpop said, you have to use remote events.

Create one in ReplicatedStorage and create a server script in ServerScriptService, here is a small example of how it would be

Script in ServerScriptService
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, humanOther)
    humanOther:TakeDamage(30)
end)
Tool script
local wind = Instance.new("Part", workspace)
wind.Shape = "Cylinder"
wind.Size = Vector3.new(0.7,30.1,74.3)
wind.BrickColor = BrickColor.new("Ghost grey")
wind.Anchored = true
wind.CanCollide = false
wind.Transparency = 1
wind.Material = "SmoothPlastic"

local Info = TweenInfo.new(5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)
local flash = game:GetService("TweenService"):Create(wind,Info,{Size = Vector3.new(1,100,100)})
local player = game:GetService("Players").LocalPlayer

local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hi = character:WaitForChild("HumanoidRootPart")
local tool = script.Parent

local swing1 = Instance.new("Animation")
swing1.AnimationId = "rbxassetid://7193950823"
local wham1 = humanoid:WaitForChild("Animator"):LoadAnimation(swing1)

local swingn2 = Instance.new("Animation")
swingn2.AnimationId = "rbxassetid://7118111810"
local whamn2 = humanoid:WaitForChild("Animator"):LoadAnimation(swingn2)

function swingClick2()
    wham1:Play()
    wait(1)
    wind.CFrame = CFrame.new(hi.Position)
    local rotate = CFrame.Angles(0, math.rad(0), math.rad(90))
    wind.CFrame = wind.CFrame:ToWorldSpace(rotate)
    flash:Play()
    wind.Transparency = .1
    wait(.2)
    wind.Transparency = .3
    wait(.2)
    wind.Transparency = .6
    wait(.2)
    wind.Transparency = 1
end

function swingnClick1()
    whamn2:Play()
end

wind.Touched:Connect(function(partOther)
    local humanOther = partOther.Parent:FindFirstChild("Humanoid")
    if humanOther and humanOther.Parent ~= tool.Parent then
        game.ReplicatedStorage.RemoteEvent:FireServer(humanOther)
    end
end)

local Equipped = false
tool.Equipped:Connect(function() Equipped = true end)
tool.Unequipped:Connect(function() Equipped = false end)
game:GetService("UserInputService").InputBegan:Connect(function(Input)
    if not Equipped then return end
    if Input.UserInputType == Enum.UserInputType.MouseButton1 then swingnClick1()
    elseif Input.UserInputType == Enum.UserInputType.MouseButton2 then swingClick2()
    end
end)

It’s not safe at all, but it’s a good start.
More information: Bindable Events and Functions | Roblox Creator Documentation

1 Like

I fixed the sword damage, I welded a part to the sword. though now the main issue is the shockwave…