Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

0

Please explain your question more!

0

Some other script might be cloning it

2 answers

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.