today I learned how to script a simple sword with sounds but in studio the dummy takes damage and the slash sound plays but in the real game when I click it does the animation but not the damage or the sound...
can anyone help me please? (here is the sword script below... :) )
Here is the Damage script (Script)
script.Parent.Handle.Touched:Connect(function(p) if script.Parent.CanDamage.Value == true then --i have a bool value in the tool called "Can Damage" and if its true the sword does damage script.Parent.CanDamage.Value = false --will autimaticly turn false for a debounce (so the person wont take a million hits per second!) local ehum = p and p.Parent:FindFirstChild("Humanoid") or p.Parent.Parent:FindFirstChild("Humanoid") --this line allows the enemie to take damage even thogh they have a hat or not... if ehum then --if the statment above is true then ehum:TakeDamage(18) -- the humanoid or person hit by this should receive 18 damage script.Parent.Handle.Sound:Play() -- Whoos! the slash should play (but currently... its not in the real game :( ) end end end)
and here is the actual sword script (Local Script)
local canattack = true local an1 = false --script.Parent.Equipped:Connect(function() --local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle) --local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack) -- --idle:Play() --end) script.Parent.Activated:Connect(function() --local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle) local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack) local attack2 = script.Parent.Parent.Humanoid:LoadAnimation(script.secAttack) if canattack == true then--and an1 == false then attack:Play() --idle:Stop() canattack = false wait(.7) attack:Stop() ---idle:Play() canattack = true script.Parent.CanDamage.Value = true an1 = true -- elseif canattack == true and an1 == true then -- attack2:Play() -- --idle:Stop() -- canattack = false -- wait(1) -- attack2:Stop() -- i tryed to make a second animation happen after the first but it was a fail... -- ---idle:Play() -- so the script ends here... -- canattack = true -- script.Parent.CanDamage.Value = true -- an1 = false end end)
Hello Tizzel! You're changing the value using the localscript. The server won't see it. I suggest using remote events.
Script:
local Remote = Instance.new("RemoteEvent", script.Parent) local CanDamage = script.Parent:WaitForChild("CanDamage") Remote.OnServerEvent:Connect(function(Player) CanDamage.Value = true end) script.Parent.Handle.Touched:Connect(function(p) if CanDamage.Value == true then CanDamage.Value = false local ehum = p and p.Parent:FindFirstChild("Humanoid") or p.Parent.Parent:FindFirstChild("Humanoid") if ehum then ehum:TakeDamage(18) script.Parent.Handle.Sound:Play() end end end)
LocalScript:
local Remote = script.Parent:WaitForChild("RemoteEvent") local canattack = true local an1 = false script.Parent.Activated:Connect(function() local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle) local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack) local attack2 = script.Parent.Parent.Humanoid:LoadAnimation(script.secAttack) if canattack then attack:Play() canattack = false wait(.7) attack:Stop() canattack = true Remote:FireServer() an1 = true end end)
Also for animations, if yours doesn't work, try to use my function :P
local Player = game:GetService("Players").LocalPlayer local function PlayAnimation(ID) local human = Player.Character:WaitForChild("Humanoid") local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/Asset?ID=" .. ID local track = human:LoadAnimation(animation) track.Priority = Enum.AnimationPriority.Action track:Play(0.1, 1, 2) track.Stopped:Wait() end -- You would call it like that: PlayAnimation(AnimationId)