I have been scripting a gamepass team change, but for some reason it will not spawn me on the correct team spawnpoint.
I get no errors for some reason.
local player = script:FindFirstAncestorOfClass("Player")
local mps = game:GetService("MarketplaceService")
script.Parent.MouseButton1Click:Connect(function()
if mps:UserOwnsGamePassAsync(player.UserId, 7916077) then
player.Team = game.Teams.Team2
end
end)
Anything I am missing?
Thank you!
3 Likes
Your issue is that you’re not using any remotes at all. When you try to change your team on the client, it won’t replicate onto the server. So when the player respawns, the server will think that they’re still on their old team. Add this into your function ;
RemoteEvent:FireServer() -- This remote will request the server to change the player's team.
On the server, add this:
local MarketplaceService = game:GetService("MarketplaceService")
RemoteEvent.OnServerEvent:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, 7916077) then
player.Team = game:GetService("Teams").Team2
player:LoadCharacter()
end
end)
You can learn more about client - server communication here!
P.S, on line 1 inside your local script, you should do this instead:
local player = game:GetService("Players").LocalPlayer
8 Likes
I was trying remote events but it never worked for me.
Thank you!
I also accidentally fixed it by adding a “if” statement