What do you want to achieve? team changer that changes your team if you got the gamepass.
What is the issue? Not reacting working even if you don’t have the gamepass
What solutions have you tried so far? Haven’t found yet.
The client that connected to the button
local id = 21404026
game.Players.PlayerAdded:Connect(function(Player)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, id) then
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.TeamChanger:FireServer(script.Parent.D.Text)
print("..Player ..")
end)
end
end)
local id = 21404026
local Player = game:GetService("Players").LocalPlayer
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, id) then
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.TeamChanger:FireServer(script.Parent.D.Text)
print("..Player ..")
end)
end
If im not mistaken, You shouldn’t check if the player owns a gamepass inside a local script, as it makes it easily exploitable, do this check on the server script instead
local id = 21404026
game.Players.PlayerAdded:Connect(function(Player)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, id) then
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.TeamChanger:FireServer(script.Parent.D.Text)
print("..Player ..")
end)
end
end)
Working script:
local id = 0000
script.Parent.MouseButton1Click:Connect(function()
if game.MarketPlaceService:UserOwnsGamepassAsync(game.Players.LocalPlayer.UserId,id) == true then
game.ReplicatedStorage:WaitForChild("TeamChanger"):FireServer(script.Parent.D.Text)
end
end)
You cannot get game.Players.PlayerAdded from a local script, second you cannot tell player, you can only tell local player which means client from a local script
You can use game.Players.PlayerAdded on a local script, tough you wont get a response from your own character since by the time the local script executes, your player will have already loaded in the server.