Need help with trip all players script

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)

im no pro but you need to have some connection to MarketPlaceService or else it will trip people without the pass

man, that’s not what i’m talking about ‘-’

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.

1 Like

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)

2 Likes

oh my gosh so advanced lol, but i will make the marketplace service.

tip:
MarketPlaceService and other related things go into a localscript
GUI goes in a localscript

Anything which affects other players in a normal script.

Market stuff can also go into the GUI script for simplicity

You need remoteevents in ReplicatedStorage to trigger the serverscript to trip the players

I noticed that yeah your sit script is located in the GUI localscript which will not work.

You need a remoteevent between the localscript and the serverscript in which will trip the players

ok

seriously, this word limit is bad ngl

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.

1 Like

Thx for the script engineer_gaming!! I really apreciatte that!!

I think you made a mistake with this if statement:

			if not player then
				local Humanoid : Humanoid = v.Character:WaitForChild("Humanoid")
				Humanoid.Sit = true
			else 
				print("yay")
			end

It should be:

			if player ~= v then
				local Humanoid : Humanoid = v.Character:WaitForChild("Humanoid")
				Humanoid.Sit = true
			else 
				print("yay")
			end

oh thx for fixing the bug. i really apreciatte that!!!