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

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
Ad

Answer this question