Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
LuaDLL 253 Moderation Voter
6 years ago

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)
0
sadly the same thing is happening to me TheS3cret 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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.

0
The core is a part in the game that players have to destroy LuaDLL 253 — 6y
0
Is the sword able to damage players? Does that work? User#20158 0 — 6y
Ad

Answer this question