Hello fellow devs I need help with one of my scripts it is giving me a error (Attempted index nill with UserId) and I have a player variable which links to to the id
Help as soon as possible would be nice
You’re trying to get a local player from a script, you should change it to a local script and it should work. Though I would still handle the changes on the server if it’s needed.
1 Like
as @TheDCraft said change this to a localscript, but this will be easily exploited cuz exploiters can change their user id for example to the owner ID and the localscript will think that you’re the owner like you would probably have the gamepass, so the gamepass would really work for them.
so a quick fix for this is
Create A Remote Event and place it in ReplicatedStorage.
– LocalScript
script.Parent.MouseButton1Down:Connect(function()
game.ReplicatedStorage.Remote:FireServer()
end)
– ServerScript
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassId = 68968922
game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(plr)
if MarketPlaceService:UserOwnsGamePassAsync(plr.UserId,gamepassId) then -- not sure whats after this part ru trying to check if the player has either gamepass 1 or gamepass2?
game.Players:FindFirstChild(plr).TeamColor = BrickColor.new("Navy blue")
game.Workspace:FindFirstChild(plr).Character.Humanoid.Health = 0
else -- elseif they don't have the gamepass then
MarketPlaceService:PromptGamePassPurchase(player,gamepassId) -- they get prompted
end)