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

Help with joining VIP script?

local vipPass = 231935192
local ultraVipPass = 231935475

game.Players.PlayerAdded:connect(function(player)
	if game.GamePassService:PlayerHasPass(player, ultraVipPass) then
		local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 10000
		end
		player.CharacterAdded:connect(function(char)
			if char:WaitForChild("Humanoid") then
				char.Humanoid.MaxHealth = 200
				char.Humanoid.Health = 200
				char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed + 4
			end
		end)
	elseif game.GamePassService:PlayerHasPass(player,vipPass) then
		local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 5000
		end
		player.CharacterAdded:connect(function(char)
			if char:WaitForChild("Humanoid") then
				char.Humanoid.MaxHealth = 150
				char.Humanoid.Health = 150
			end
		end)
	end
end)

I have this script inside ServerScriptStorage and I was whenever a VIP joins a server they get all the perks. It works, but if you leave and rejoin the same server then you don't get these perks. How can I make it so you get these perks every time you enter a new server as well as the same server you were in a few minutes ago?

1 answer

✓ Accepted answer

There's no reason why they shouldn't get this when they rejoin, but I can point out a few errors

1) - I HIGHLY suggest using the PlayerOwnsAsset function, rather than the PlayerHasPass function. Because it returns live results from the website, while the PlayerHasPass function returns cached results. Meaning you won't have to rejoin the game to get the effects if you bought the gamepass during gameplay.

2) - You're giving the character a health boost no matter what, conditionals do NOT effect whether or not events fire! meaning that your CharacterAdded event will fire reguardless of if the conditional is true or false, hence you getting a health boost no matter what.

local vipPass = 231935192
local cashStorage = game.ServerStorage.MoneyStorage
local cashAwarded = false
--edit--
local ms = game:GetService('MarketplaceService')
--edit--

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		if ms:PlayerOwnsAsset(player,vipPass) and not cashAwarded then
			local cash = cashStorage:FindFirstChild(char.Name)
			if cash then
				cash.Value = cash.Value + 5000
				cashAwarded = true
			end
			local hum = char:WaitForChild('Humanoid')
			--edit[2]--
			hum.MaxHealth = 150
			hum.Health = 150
			--edit[2]--
		end
	end)
end)

10 comments

0

it says ms is unknown global?

0

and another thing. I have two VIPs, I only used one. How can I get it to work so it works for both a VIP and UltraVIP. I have editted my answer with my original with both vips.

0

Sorry I didn't define ms.

0

Should my thing actually work without any problems? I think its cause of the moneystorage in ServerStorage, but idk. I just want if you leave and rejoin that same server you get the cash and health again

0

I'm not going to help with adding another VIP to it since it's not your original question. This code should work perfectly.. what errors are you getting?

0

there are no errors

0

I have one problem though, when you join , your maxhealth changes to 150, BUT your health dosent, so you start of with half your health and have to wait till it gets to 150

0

What do you mean 'wait' until it gets to 150? It should change with little to no yeild from when the character spawn

0

well the character spawns with 100 health and 150 max health, so the player has to wait for it to load

0

Sorry, it's because I defined the health before the MaxHealth was defined. I edited it so it should work now(:

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