Hello, I want to make a speed gamepass, but my script doesn’t work.
This is the script, and it is located inside ServerScriptService.
local player = game.Players.LocalPlayer
local character = player.CharacterAdded()
local humanoid = character.Humanoid
game.Players.PlayerAdded:Connect(function(player)
local success, boughtGamepass = pcall(function()
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 19237735)
end)
if success and boughtGamepass then
humanoid.Walkspeed = 28
end
end)
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local success, boughtGamepass = pcall(function()
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 19237735)
end)
if success and boughtGamepass then
humanoid.Walkspeed = 28
end
end)
local Serv = game:GetService("GamePassService")
local MServ = game:GetService("MarketplaceService")
workspace.ChildAdded:Connect(function(char)
local getpl = game:GetService("Players"):FindFirstChild(char.Name)
if char:FindFirstChild("HumanoidRootPart") ~= nil then
if MServ:UserOwnsGamePassAsync(getpl.UserId, 19237735) then
char.Humanoid.WalkSpeed = 28
end
end
end)
The problem in your script is it probably stops working in first 3 lines, first off all LocalPlayer doesn’t exists on server so it will return nil and there’s no way to do player.CharacterAdded() you can do player.CharacterAdded:Wait() instead but let’s remove first 3 lines and do everything inside PlayerAdded and CharacterAdded events…
local function CheckGamepass(player)
local success, boughtGamepass = pcall(function()
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 19237735)
end)
if success and boughtGamepass then
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.Walkspeed = 28
else
player.CharacterAdded:Wait()
player.Character:WaitForChild("Humanoid")
player.Character.Humanoid.Walkspeed = 28
end
end
end
game.Players.PlayerAdded:Connect(function(player)
CheckGamepass(player)
player.CharacterAdded:Connect(function(character)
CheckGamepass(game.Players:GetPlayerFromCharacter(character))
end)
end)
If you don’t use CharacterAdded event it will not work after you respawn so it’s better to use CharacterAdded too. Let me know if it helps
You said game.Players.LocalPlayer on the top. I’m pretty sure you can only say this in a local script since the local script is from the local player. This should also give an error with the humanoid because game.Players.LocalPlayer does not work with server scripts.