Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Sword doesn't work when cloned into the Backpack?

Asked by 2 months ago

Ok, so I have a sword shop that when I press the button the sword from the ReplicatedStorage goes to the Backpack. That works fine. The problem is that it doesn't seem to deal damage when I activate it even though it had worked fine when I tested it by putting it in the Starterpack. Please help.

Sword client (a local script inside the tool/sword):

wait(0.6)

script.Parent.Equipped:Connect(function()
    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
    wait(0.1)
idle:Play()
script.Parent.Unequipped:Connect(function()
idle:Stop()
end)
end)

--//Attacking Animations\\--
local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local CanAttack = true
local Anim_Name = "Attack"
local Audio = script.Parent:WaitForChild("Handle"):WaitForChild("Swing")
local Attack_Animations = script.Parent:WaitForChild("Animations")
local Attack_Num = 1
local blade = script.Parent:WaitForChild("ScytheBlade")
local RE = Tool.RemoteEvent
local OneHitEvent = Tool.OneHitEvent
local OneHit = Tool.OneHit

blade.Touched:Connect(function(hit)
    if CanAttack == false and OneHit.Value and script.Parent.Parent == game.Players.LocalPlayer then
        OneHitEvent:FireServer()
            RE:FireServer()
    end
end)

Tool.Activated:Connect(function()
    OneHit.Value = true
        local Animation = script.Parent.Parent.Humanoid:LoadAnimation(Attack_Animations[Anim_Name..Attack_Num])
        if CanAttack == true then
            CanAttack = false
            Animation:Play()
            Audio:Play()
            wait(0.7)
            CanAttack = true
            if Attack_Num == 1 then
                Attack_Num = Attack_Num + 1
                else if Attack_Num == 2 then
                    Attack_Num = 1
                end
            end
        end
end)

Tool.Deactivated:Connect(function()
    script.Parent.Equipped:Connect(function()
    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
    wait(0.1)
idle:Play()
script.Parent.Unequipped:Connect(function()
idle:Stop()
end)
end)
end)

Server script (a normal script inside the tool):

local RemoteEvent = script.Parent.RemoteEvent
local Damage = 10
local blade = script.Parent.Blade
local OneHit = script.Parent.OneHit
local RE = script.Parent.OneHitEvent

local TD = true

RE.OnServerEvent:Connect(function(plr)
    OneHit.Value = true
end)

RemoteEvent.OnServerEvent:Connect(function(plr)
    blade.Touched:Connect(function(h)
        if h:IsA("BasePart") and h.Parent:FindFirstChild('Humanoid') and h.Parent.Name ~= plr.Name and TD and OneHit.Value then
            TD = false
            local Humanoid = h.Parent.Humanoid
            Humanoid:TakeDamage(Damage)
            local indicator = game:GetService("ReplicatedStorage"):FindFirstChild("DmgIndicator") -- we put the dmgindicator which in in the replicatedstorage inside a variable
                if indicator then -- we check whether the indicator exists, if so then...
                    local gui = indicator:Clone() -- we clone it and store the cloned version inside a variable
                    gui.Parent = h.Parent:FindFirstChild("HumanoidRootPart") -- we put the cloned version inside the enemy's rootpart
                    gui.Damage.Text = "-"..tostring(Damage) -- we set the damage text to the damage we'll deal                  
                    gui.StudsOffset = Vector3.new(math.random(-2, 2), math.random(-2, 2), math.random(-2, 2)) -- we position our gui randomly on the enemy's body (between -2 and 2 studs)
                    wait(0.75)
                    game.Debris:AddItem(gui,0.1) 
            OneHit.Value = false
            TD = true
            end
            end
    end)
end)

There are 2 remote events: one named OneHitEvent one named RemoteEvent

Also, there is a bool value named OneHit

In the output, it states no errors but there clearly is.

0
Try to Disable and Enable scripts when the sword is given. vovik 9 — 2mo

1 answer

Log in to vote
0
Answered by 2 months ago
Edited 2 months ago

Any scripts that come from ReplicatedStorage will not transfer well to Workspace.

Try cloning it from Workspace or lighting.

Edit: Have to tool in StarterPack and disable it. Enable when the player should use/have it.

Happy scripting, Tim

0
Sorry, it didn't work MelodicSea5914 21 — 2mo
0
Did you do it from lighting, or workspace? TheLeader_TimJunior 144 — 2mo
Ad

Answer this question