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

Ability does not disappear when player dies?

Asked by 5 years ago
Edited 5 years ago

So when a player dies then uses the ability, it stays there forever. Both scripts are inside the tool

--Server Script--
local tween = game:GetService("TweenService")
local casting = false

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
    if casting == true then return end
    casting = true

    local iceSpikes = game.ReplicatedStorage.LightCage:Clone()
    local dmg = 3
    --Pre position
    iceSpikes:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame)
    iceSpikes.Parent = workspace
    local endPositions = {Position = {}, Orientation = {}}
    for i,v in pairs(iceSpikes.Spikes:GetChildren()) do
        endPositions["Position"][i] = v.Position
        endPositions["Orientation"][i] = v.Orientation
        v.CFrame = CFrame.new(iceSpikes.Center.Position)
    end

    --Activate
    wait(0)
    local Sound = script.Parent.Lightning
    Sound:Play()
    for i,v in pairs(iceSpikes.Spikes:GetChildren()) do
        v.Orientation = endPositions["Orientation"][i]
        tween:Create(v, TweenInfo.new(0), {Position = endPositions["Position"][i]}):Play()
    end

    --Attack
    for i,v in pairs(iceSpikes.Spikes:GetChildren()) do
        v.Touched:Connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild("AlreadyHit") and not hit:IsDescendantOf(player.Character) then --Check if its a player
                local enemyHumanoid = hit.Parent:FindFirstChild("Humanoid")
                enemyHumanoid:TakeDamage(dmg)
            end
        end)
    end

    --Remove
    wait(5)
    Sound:Stop()
    iceSpikes:Destroy()
    casting = false
    wait(2)
    if iceSpikes.Parent == workspace then
        iceSpikes:Destroy()
    end
end)

--Local Script--
local tool = script.Parent

tool.Activated:Connect(function()
script.Parent.RemoteEvent:FireServer()
end)
0
Where is this server script located? inside the player character? SerpentineKing 3885 — 5y
0
Inside teh tool Justingamer700 114 — 5y

1 answer

Log in to vote
1
Answered by
Despayr 505 Moderation Voter
5 years ago

The problem is that the script is located inside the tool. When a players character dies, the tool and its descendants are also destroyed. This prevents the script from continuing.

To fix this, simply place the RemoteEvent in ReplicatedStorage, and have the ServerScript in ServerScriptService. Since the script is not inside of a tool, it will not be removed, thus it will continue, even if the players character dies.

Why have the same serverscript replicated to each tool, when it can all be controlled through just one? Having just one will also keep the lag to a minimum.

0
The other players will then not be able to ue the move when it is being used by another person Justingamer700 114 — 5y
Ad

Answer this question