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

Why doesn't my clone work after the first time?

Asked by 6 years ago
Edited 6 years ago

The problem is that when the player dies with the flag, it clones. When they spawn back in, they touch the flag to get it again. If they die with the flag, it doesn't clone anymore. I have no idea why. Here's the script:(This is a normal script with FE turned off.)

local hasFlag = false
local Thing = true
local DeBounce = true

function accessBackpack(hit)
    if hit and hit.Parent then
        local chara = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(chara)
        local backpack = player:FindFirstChild("Backpack")
        local flag = backpack:FindFirstChild("RedFlag")
        if flag and flag.Parent == backpack and hasFlag == true then
            return "RedFlag"
        else
            return print("No flag")
        end
    end
end 

script.Parent.RedFlag.Handle.Touched:Connect(function(char)
    if DeBounce == true then 
    DeBounce = false
    hasFlag = true
    if char and char.Parent then
        player = game.Players:GetPlayerFromCharacter(char.Parent) 
        if player then--check if they are a player
            if char.Parent:FindFirstChild("Humanoid") then 
                if char.Parent.Humanoid.Health > 0 then--if they are still alive
                    print(player.Name .. " has the Red Flag!")
char.Parent:FindFirstChild("Humanoid").Died:Connect(function()
    print(player.Name.. " has died with the Red Flag!")
    if char.Parent:FindFirstChild("RedFlag") or accessBackpack(char) and hasFlag == true then --if they die and they have the flag in their hand or backpack
    hasFlag = false
    local FlagClone = game:GetService("ServerStorage"):WaitForChild("RedFlag"):Clone()--the flag gets cloned and put into workspace
        FlagClone.Parent = game.Workspace
        FlagClone.Handle.CFrame = CFrame.new(char.Parent.Head.Position)
        FlagClone:WaitForChild("Handle").Anchored = true
        Thing = false
        wait(3)
        Thing = true
 FlagClone.Handle.Touched:Connect(function(char2)
    wait(Thing)
    if FlagClone.Parent.Parent == game.Workspace then
        FlagClone.Handle.Anchored = false
    end
end)
    end                                    
end)
                end
            end
        end
    end
    end
DeBounce = true
end)

Btw, my DeBounce still isn't working, and the output has no errors, but says what it needs to say. Whenever I touch the flag, the output says-Rilgundam has the Red Flag!x3-. When I die with the flag, it says-Rilgundam has died with the Red Flag!x3-. And it clones three times. Please help me.

0
Read my bio. How hard could this be?!?! hiimgoodpack 2009 — 6y
0
What is wrong with it rilgundam 65 — 6y
0
What did i do rilgundam 65 — 6y
0
Local player? I just fixed that rilgundam 65 — 6y
View all comments (5 more)
0
READ MY BIO CAREFULLY hiimgoodpack 2009 — 6y
0
Just tell me rilgundam 65 — 6y
0
Idk what I did wrong rilgundam 65 — 6y
0
Is it indenting rilgundam 65 — 6y
0
Can you please just help me rilgundam 65 — 6y

Answer this question