What do i want: I want to make the players trip when he buy the trip gamepass. What’s the problem? But the problem is: I don’t know how can i make all the players trip except who bought the trip.
Here’s my code:
local UI = script.Parent.Parent.Parent
local Button = script.Parent
local Players = game:GetService("Players")
Button.MouseButton1Click:Connect(function()
for i, v in pairs(Players:GetChildren()) do
local Humanoid : Humanoid = v.Character:WaitForChild("Humanoid")
Humanoid.Sit = true
end
end)
i want to make when the player buy the thing, all the players trip’s which i already did, what i want is who bought the trip, don’t trip together with the other players.
You need remoteevents between a localscript (GUI) and serverscript (the one to kick the players) alongside the MarketPlaceService in a localscript when the player does purchases.
The Marketplaceservice can most likely go in the (GUI)
No, what they mean is that you must include MarketPlaceService to make sure that only people with the gamepass can trigger the trip all. The code given looks to have nothing stopping some normal person without the gamepass from just clicking the button and triggering the trip all. Anyway, I believe your code is almost right, but just have it check if the player is not equal to the game.Players.LocalPlayer, and it will make it so it only sits players who aren’t the player who clicked it. (Also like SunnyFlops said, for it to sit them serverside, make sure the code triggers a remote event)
Here is a sample bit of code for what you said
LocalScript(should be in the UI)
local UI = script.Parent.Parent.Parent
local Button = script.Parent
Button.MouseButton1Click:Connect(function()
game.ReplicatedStorage.YourRemoteEvent:FireServer()
end)
Script(should be in ServerScriptStorage)
local MarketService = game:GetService("MarketplaceService")
game.ReplicatedStorage.YourRemoteEvent.OnServerEvent:Connect(function(player)
if MarketService:UserOwnsGamePassAsync(player.UserId, yourGamepassID) then
for i, v in pairs(game.Players:GetChildren()) do
if not player then
local Humanoid : Humanoid = v.Character:WaitForChild("Humanoid")
Humanoid.Sit = true
else
print("yay")
end
end
end
end)
Please keep in mind, that most likely you will want to have some sort of cooldown realistically, so you would probably want to have the game store a table of players and when they last activated it so that you can make sure people do not spam the trip thing. Also, for trips, you could try looking into setting humanoid state to fallingdown and gettingup. Finally, make sure any checks for stuff like MarketPlaceService are server side, as otherwise clients could potentially trigger a remoteevent like this without actual ownership of the gamepass.