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
