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

Script doesn't give tools after user rejoins?

So I'm making this boss fight game, and there's this script that is supposed to give the players their weapons depending on the badges they have.

game.Players.PlayerAdded:connect (function(Player)
	
	local Badge = game:GetService('BadgeService')
	local Weapons = game.ReplicatedStorage:WaitForChild("Weapons")
	
	
	if Badge:UserHasBadge(Player.userId, 543912061) then
		Weapons.Lewis:Clone().Parent = Player.Backpack
		Weapons.Lewis:Clone().Parent = Player.StarterGear
	end
	
	if Badge:UserHasBadge(Player.userId, 648868230) then
		Weapons.Spoon:Clone().Parent = Player.Backpack
		Weapons.Spoon:Clone().Parent = Player.StarterGear
	end
	
	if Badge:UserHasBadge(Player.userId, 654113969) then
		Weapons.Radon:Clone().Parent = Player.Backpack
		Weapons.Radon:Clone().Parent = Player.StarterGear
	end
	
	if Badge:UserHasBadge(Player.userId, 660341744) then
		Weapons.Polearm:Clone().Parent = Player.Backpack
		Weapons.Polearm:Clone().Parent = Player.StarterGear
	end
	
	
end)

However, according to several reports, the script does not work when the user rejoins the server.

I have attempted to make a GUI that gives the tools, but unfortunately it cannot query for badges for some odd reason.

How would I fix this so that it would always give the player their tools when they joined?

1 answer

✓ Accepted answer

The problem with PlayerHasPass is that it can return cached data. It would be better if you used PlayerOwnsAsset.

Side notes

When the player joins it will take a small amount of time for them to get a backpack ect so it would be best to use WaitForChild.

Lastly userId is deprecated in favor of UserId.

Example script:-

local Badge = game:GetService('MarketplaceService')
local Weapons = game.ReplicatedStorage:WaitForChild("Weapons")

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

    if BadgePlayerOwnsAsset(Player.UserId, 543912061) then
        Weapons.Lewis:Clone().Parent = Player:WaitForChild('Backpack')
        Weapons.Lewis:Clone().Parent = Player:WaitForChild('StarterGear')
    end

    if Badge:PlayerOwnsAsset(Player.UserId, 648868230) then
        Weapons.Spoon:Clone().Parent = Player:WaitForChild('Backpack')
        Weapons.Spoon:Clone().Parent = Player:WaitForChild('StarterGear')
    end

    if Badge:PlayerOwnsAsset(Player.UserId, 654113969) then
        Weapons.Radon:Clone().Parent = Player:WaitForChild('Backpack')
        Weapons.Radon:Clone().Parent = Player:WaitForChild('StarterGear')
    end

    if Badge:PlayerOwnsAsset(Player.UserId, 660341744) then
        Weapons.Polearm:Clone().Parent = Player:WaitForChild('Backpack')
        Weapons.Polearm:Clone().Parent = Player:WaitForChild('StarterGear')
    end


end)

I hope this helps.

1 comment

0

Had to edit it a little but it works now! Thanks!

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