Hello, I am trying to make a GUI that lets you change the team, but only if you are in the group and have a rank OR if you have the gamepass for it, I’ve found a script but it’s not really working, here it is. Please can someone help me, I am making a SCP game and I do not find it anywhere else.
Here’s the script, I’ve added the script into the button that lets you change the team.
game.Players.PlayerAdded:Connect(function(player)
if game:GetService("MarketPlaceService"):PlayerOwnsAsset("gamepassidcomeshere") then
if player:GetRoleInGroup(numbeidrofthegroupcomeshere) == "nameofrolecomeshere" then
local player = script.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:connect(function()
player.Team = game.Teams:FindFirstChild("Chaos Insurgency")
player.Character.Humanoid.Health = 0
end)
end
end
end)
game.Players.PlayerAdded:Connect(function(player)
if game:GetService("MarketPlaceService"):PlayerOwnsAsset(player.UserId, "gamepassidcomeshere") or player:GetRoleInGroup(numbeidrofthegroupcomeshere) == "nameofrolecomeshere" then
local player = script.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:connect(function()
player.Team = game.Teams:FindFirstChild("Chaos Insurgency")
player.Character.Humanoid.Health = 0
end)
end
end)
You should place this line inside the MouseButton1Click function, doing it this way will allow a player that bought the game pass while playing the game to access the team without rejoining.
local gamepassId = 0
local groupId = 0
local minRank = 0
game.Players.PlayerAdded:Connect(function(Player)
script.Parent.MouseButton1Click:connect(function()
if game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(Player.UserId,gamepassId) or Player:GetRankInGroup(groupId) >= minRank then
Player.Team = game.Teams:FindFirstChild("Chaos Insurgency")
Player.Character.Humanoid.Health = 0
else
game:GetService("MarketPlaceService"):PromptGamePassPurchase(Player.UserId,gamepassId)
end
end)
end)
This code will check if the player owns the game pass each time the button is pressed, if the player does not own the game pass or has the required rank in the group the script will prompt the option o purchase the game pass.
Thank you for the script, but it sadly doesn’t work, I put the script into a button as a normal script (not LocalScript) but ye it’s not working, even if I am in the group it does nothing. And it also doesn’t promt a gamepass purchase. Or would you recommend me another way for team changing, like using remote event??
My script was intended to go on the Server Script Service, but seems that you want to place it inside the PlayerGui.
Just a modification of the script for the Player Gui:
local gamepassId = 0
local groupId = 0
local minRank = 0
local Player = script.Parent -- Player Location here
script.Parent.MouseButton1Click:connect(function()
if game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(Player.UserId,gamepassId) or Player:GetRankInGroup(groupId) >= minRank then
Player.Team = game.Teams:FindFirstChild("Chaos Insurgency")
Player.Character.Humanoid.Health = 0
else
game:GetService("MarketPlaceService"):PromptGamePassPurchase(Player.UserId,gamepassId)
end
end)
But I strongly recommend using Remote Events (are safer)
But in that case I recommend you to use Remote Event, are safer against exploiters.
Place a Remote Event on the Replicated Storage
Place a Local script to fire the event:
local event = game.ReplicatedStorage:FindFirstChild("Event") -- Your event location here
script.Parent.MouseButton1Click:connect(function()
event:FireServer()
end)
And then a Server Script inside Server Script Service
local gamepassId = 0
local groupId = 0
local minRank = 0
local Event = game.ReplicatedStorage.Event -- Event location here
Event.OnServerEvent:Connect(function(Player)
script.Parent.MouseButton1Click:connect(function()
if game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(Player.UserId,gamepassId) or Player:GetRankInGroup(groupId) >= minRank then
Player.Team = game.Teams:FindFirstChild("Chaos Insurgency")
Player.Character.Humanoid.Health = 0
else
game:GetService("MarketPlaceService"):PromptGamePassPurchase(Player.UserId,gamepassId)
end
end)
end)