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

Why does this script duplicate every time someone resets or dies?

Asked by 4 years ago
Edited 4 years ago

The script makes it so the player who owns the game pass gets a variety of bonuses and gears. I found out that every time your character respawns, they get the same benefits.

EX. They spawn in the game with $5k, they get killed, they respawn with $10k. I don't believe there is anything wrong with the script, but I do believe there might be something wrong with the game

local MS = game:GetService("MarketplaceService")
local VIPID = 7139894

local RS = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        if MS:UserOwnsGamePassAsync(Player.UserId,VIPID)then
            game.ServerStorage.GravityCoil:Clone().Parent=Player.Backpack
            game.ServerStorage.FirstAid:Clone().Parent=Player.Backpack
            game.ServerStorage.RocketLauncher:Clone().Parent=Player.Backpack

            local player = game.Players.LocalPlayer
            local char = Player.character
            char.Humanoid.MaxHealth = 150
            char.Humanoid.Health = 150

        local cashmoeny = game.ServerStorage.PlayerMoney:FindFirstChild(Player.Name)
        cashmoeny.Value = cashmoeny.Value + 5000

            local Head = Character:WaitForChild("Head")
            local VIP = RS:WaitForChild("VIP"):Clone()
            VIP.Adornee = Head
            VIP.Parent = Head
        end     
    end)
end)
0
Please explain your question more! BashGuy10 384 — 4y
0
Some other script might be cloning it royaltoe 5144 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Error was found in database mainframe

function onButtonClicked()
    local w = workspace:GetChildren()
    for i = 1, #w do
        if w[i].Name == "BlackHorse" or  w[i].Name == "BrownHorse" or w[i].Name == "GreyHorse" then
            w[i]:Destroy()
        end
    end
end

Ad
Log in to vote
0
Answered by
Sulfone 141
4 years ago

The script doing its task of giving $5k to a VIP player every time they spawn - this includes respawns. This is since you have cashmoeny.Value = cashmoeny.Value + 5000 always run on VIP players' CharacterAdded.

If you want VIP players to only gain the $5k on joining, one way to do it would be with a variable in the PlayerAdded function body (but outside of CharacterAdded function body) describing whether they have received the money or not. Then only give money if it says the player has not been given money, and update the variable once you give the player money.

As an example, here's some of your code with the changes made:

game.Players.PlayerAdded:Connect(function(Player)
    local given = false

    Player.CharacterAdded:Connect(function(Character)
        if MS:UserOwnsGamePassAsync(Player.UserId,VIPID) then
            if not given then
                -- section to give the player money here
                given = true
            end

            -- anything to run every time a VIP player spawns here
        end
    end)
end)

Answer this question