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

My gamepass script for adding health, walkspeed, and cash isn't working?

So I have this script in my game for making the gamepasses give weapons and it works. I want to make it so that if you have the same gamepass it gives you walkspeed, health, and cash. Can you explain where I would add it to this script and how?

if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then 
		local cashmoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
			if cashmoney then
				cashmoney.Value = cashmoney.Value + 1000000
			end

elseif GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		local char = player.Character
		char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 50
		wait()
		char.Humanoid.Health = char.Humanoid.MaxHealth

elseif GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
		local char = player.Character
		if char then
			local human = char:FindFirstChild("Humanoid")
			if human then
				human.WalkSpeed = human.WalkSpeed + 10
			end
		end

I'm adding this script above at the end of the script below. It isn't working. What is wrong?

local GamePassService = Game:GetService('GamePassService')
local PlayersService = Game:GetService('Players')
local InsertService = Game:GetService('InsertService')
local LightingService = Game:GetService('Lighting') --TODO: Use new data store service once that exists

local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ToolAssetsToLoad = WaitForChild(script, 'ToolAssetsToLoad')

local AdminTools = LightingService:FindFirstChild('AdminTools')

-----------------
--| Functions |--
-----------------

-- Makes copies of all the admin tools and puts them in target
local function CloneAdminTools(target)
	for _, tool in pairs(AdminTools:GetChildren()) do
		local toolClone = tool:Clone()
		toolClone.Parent = target
	end
end

-- When a player with the game pass joins, give them the admin tools
local function OnPlayerAdded(player)
	if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
		local starterGear = WaitForChild(player, 'StarterGear')
		CloneAdminTools(starterGear)
		if player.Character then -- They've already loaded and won't get their StarterGear until next spawn
			local backpack = WaitForChild(player, 'Backpack')
			CloneAdminTools(backpack)
		end
	end
end

1 answer

It will not move on in the script until you fix the CashMoney. To my knowledge you haven't made the IntValue to the leaderboard to even add the CashMoney. First you must appoint the new Leaderboard Section.

game.Players.PlayerAdded:connect(function(plr)
	local cashmoney = Instance.new("IntValue",  plr)
	stats.Name = 'leaderstats'
	stats.Value = 0
end)

Change this however needed.

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