The first part works but the second part with the walk speed doesn't.
local service = game:GetService("GamePassService") game.Players.PlayerAdded:connect(function(player) if service:PlayerHasPass(player,1008824264) then game.Players.LocalPlayer.leaderstats.Points.Value = game.Players.LocalPlayer.leaderstats.Points.Value + 250 end end) game.Players.PlayerAdded:connect(function(player) if service:PlayerHasPass(game.Players.LocalPlayer,1008824264) then game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 50 end end)
I noticed 2 problems with your code, so I'm gonna do my best to explain them.
Problem 1
You can't use LocalPlayer in a server script. This is because LocalPlayer is the client, and the client can't be accessed using a server script. To fix this, use the perimeter you added to the PlayerAdded function.
Problem 2
I would suggest using an elseif statement rather than 2 different PlayerAdded functions. This is because it's completely useless to make 2 PlayerAdded functions because they will both fire every time a new player joins. I also suggest using WaitForChild because if the player hasn't loaded your code will error, returning what didn't load as a nil value.
Your code should look something like this:
local service = game:GetService("GamePassService") game:GetService("Players").PlayerAdded:Connect(function(player) if service:PlayerHasPass(player, 1008824264) then player.leaderstats:WaitForChild("Points").Value = player.leaderstats:WaitForChild("Points").Value + 250 --using the player parimeter rather than localplayer elseif service:PlayerHasPass(player, 1008824264) then --elseif statement checking if they own the other pass player.Character:WaitForChild("Humanoid").WalkSpeed = 50 end end)
If this helped, make sure to accept my answer!
you don't use LocalPlayer
in a regular script, that's only for scripts that run client-side. This means it should only work in studio, because when you're testing in studio, the tester is always the localplayer. the way you want to get the player is by using the first argument in the PlayerAdded
event, which returns the player that joined
local service = game:GetService("GamePassService") game.Players.PlayerAdded:Connect(function(player) if service:PlayerHasPass(player,1008824264) then local leaderstats = player:WaitForChild("leaderstats") local points = leaderstats:WaitForChild("Points") points.Value = points.Value + 250 end end) game.Players.PlayerAdded:Connect(function(player) if service:PlayerHasPass(player, 1008824264) then player.CharacterAdded:Connect(function(character)-- runs every time the player respawns player:WaitForChild("Humanoid").WalkSpeed = 50 end) end end)