Hi, I am trying to make a sword for myself and I think I have gotten most parts. My issue now is that the damage part on the sword doesn’t become “touched”, thus failing to FireServer, which controls the damage stuff. I am not very advanced in scripting so detailed replies would be much appreciated!!
Here is a clip of what I mean
link
This is the client script
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = game.Workspace:WaitForChild(player.Name)
local rp = game:GetService("ReplicatedStorage")
local sideValue = player.PlayerGui:WaitForChild("SideValue")
local rankValue = player:WaitForChild("Rank").Value
local activateSwordDmg = rp:WaitForChild("ActivateSwordDmg")
local ready, swinging = false, false
UIS.InputBegan:Connect(function(input, gameProcessed)
local char = game.Workspace[player.Name]-- long conditions which just exit out can be made into a guard clause
if ready or gameProcessed or input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
print("left clicked")
print(rankValue)
if not char.RightHand:FindFirstChild('Weld') then
print('no sword equipped')
return
end
-- these flags tell the event when it can hit
swinging = true
ready = true
local slashAnim = Instance.new("Animation")
slashAnim.AnimationId = "http://www.roblox.com/Asset?ID=5862780080"
local loadedAnim = char.Humanoid:LoadAnimation(slashAnim)
loadedAnim:Play()
loadedAnim.Stopped:Wait()
swinging = false
wait(0.4)
ready = false
end)
local dmgpart = game.Workspace[player.Name]:WaitForChild("Sword"..rankValue):WaitForChild("DmgPart")
dmgpart.Touched:Connect(function(hit)
print("touched")
if swinging and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Humanoid"):IsA("Instance")then
print("humanoid found")
activateSwordDmg:FireServer(hit, sideValue.Value)
swinging = false
print("server fired")
end
end)
char:WaitForChild("Humanoid").Died:Connect(function()
print("dmg resetted")
dmgpart = game.Workspace[player.Name]:WaitForChild("Sword"..rankValue):WaitForChild("DmgPart")
ready, swinging = false, false
end)
The script didn’t even print “touched” so I am assuming that there is something wrong within the script itself. I also thought it was the fact that maybe dmgpart, ready, and swinging wasn’t in sync anymore when the player dies, so I added the function at the end to reset the values. But that didn’t work either. Now I am stuck and I don’t know what to do . Any help would be appreciated!