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

I'm getting double tools in my script, no errors at all, how do I fix this?

So I am working on a group item giver, it works, besides the fact it gives two staff cards instead of one interview card and one staff card.

local groupId = 4933174

local tool = game.ServerStorage["Interview Card"]

function onPlayerSpawned(player) if player:IsInGroup(groupId) then tool:Clone().Parent = player.Backpack end end

game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function() onPlayerSpawned(player) end) end)

function onPlayerSpawned(player) if player:GetRankInGroup(groupId) >= 12 then tool:Clone().Parent = player.Backpack end end

local tool2 = game.ServerStorage["Staff Card"]

function onPlayerSpawned(player) if player:IsInGroup(groupId) then tool2:Clone().Parent = player.Backpack end end

game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function() onPlayerSpawned(player) end) end)

function onPlayerSpawned(player) if player:GetRankInGroup(groupId) >= 7 then tool2:Clone().Parent = player.Backpack end end

Any idea how to fix this?

1 answer

✓ Accepted answer

becourse u say 2 time the he must clone it

local groupId = 4933174

local tool = game.ServerStorage["Interview Card"]

function onPlayerSpawned(player)   --<-- only need this one time
	if player:IsInGroup(groupId) then
		 tool:Clone().Parent = player.Backpack --- one time
	end
end

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function()
		 onPlayerSpawned(player) 
	end)
end)

function onPlayerSpawned(player)  --<-- this is double
	if player:GetRankInGroup(groupId) >= 12 then 
		tool:Clone().Parent = player.Backpack  -- two time
	end
end

solution:

local groupId = 4933174

local tool = game.ServerStorage["Interview Card"]
local tool2 = --- ure choise

function onPlayerSpawned(player) 

	if player:IsInGroup(groupId) and player:GetRankInGroup(groupId) >= 12 then -- the and say both has to be. u can also use or to see if one of both is. but only use 1 time tool:Clone() else it clones 1 a sec time

		 tool:Clone().Parent = player.Backpack --- one time

	end
	
	--<-- put here the other if with the other tool: tool2
	
end

game.Players.PlayerAdded:connect(function(player)

	player.CharacterAdded:connect(function()

		 onPlayerSpawned(player) 

	end)

end)

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