Hey guys, I'm stuck in this script

I’m trying to make a Time Stop script that would anchor everyone but the user, and it would unanchor at a certain amount of time.
The problem is that i’m stuck at this. I’m looking for help on this.


local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = humanoid:LoadAnimation(run)
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
	    if not gameProcessed then
	        if Input.KeyCode == Enum.KeyCode.F then

2 Likes

Then just use GetPlayers and find their characters, then anchor their HumanoidRootPart or Head.

1 Like

Sorry, I’m new to scripting, how would I make this work?

1 Like
for i, v in ipairs (game.Players:GetPlayers()) do
if v.Name ~= "Someone" then -- The person that's immune
v.Character.HumanoidRootPart.Anchored = true
end
end

Sorry I’m on my phone so I might have typed something wrong.
The screen keyboard is too small.

1 Like
game:GetService("Players")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = Humanoid:LoadAnimation(run)
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
	    if not gameProcessed then
		        if Input.KeyCode == Enum.KeyCode.F then
for i, v in pairs (game.Players:GetPlayers()) do
if v.Name ~= "Someone" then -- The person that's immune
v.Character.HumanoidRootPart.Anchored = true			
					runtrack:Play()
				end
			end
		end
	end
	end)

So this is my script right now, i’ll try it out.

1 Like

Okay, good news and bad news. The script works, the problem is I can only run it in a local script
And I get anchored aswell…

local Lighting = game.Lighting
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
game:GetService("Players")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = Humanoid:LoadAnimation(run)
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
	    if not gameProcessed then
		        if Input.KeyCode == Enum.KeyCode.F then
			runtrack:Play()
			workspace.Sound2:Play()
for i, v in pairs (game.Players:GetPlayers()) do
if v.Name ~= "Someone" then -- The person that's immune
					v.Character.HumanoidRootPart.Anchored = true
					Lighting.ColorCorrection.Saturation = -1
					Lighting.bruh.Saturation = -1
					wait(2)
					Lighting.ColorCorrection.Contrast = 2
					Lighting.ColorCorrection.Saturation = 0
					wait(3)
					Lighting.ColorCorrection.Contrast = 0
					Lighting.bruh.Saturation = 0
					for i, v in pairs (game.Players:GetPlayers()) do
if v.Name ~= "Someone" then -- The person that's immune
					v.Character.HumanoidRootPart.Anchored = false
				
				end
			end
		end
	end
		end
	end
	end)
1 Like

the check for v.Name ~= “Someone” should be

v ~= game.Players.LocalPlayer

that way it doesn’t anchor your player.
Note this script will make it seem like players are lagging, as they will freeze then go to their new position once unanchored, as on their screen they are not anchored. If you want it to anchor players without it only being on the player that used the effect’s screen, use a remoteEvent, with the same script on the server but the check line checks like this instead:

Event.OnServerEvent:Connect(function(Player, ...) --... is just a placeholder for whatever arguments you might pass through the function, such as the effect
    --loop through players
    if v ~= Player then
        --do effect
    end
end)

--Client:

if Input.KeyCode == Enum.KeyCode.F then
    Event:FireServer(...) -- Again, a placeholder, this can send the effect name or something like that.
end
1 Like

Could you explain it a bit more, or put it in my script for an example? I’m very new to scripting.

(Yes, I have not used remote events)

1 Like

Remote Event Documention
FilteringEnabled

You need to use a remote event to make sure the change replicates to all clients, so that they don’t get anchored and appear to lag back into their real position once unanchored.
You need to let the server know you’re using an effect, so you :FireServer("EffectName") and the server listens with this code:

Event.OnServerEvent:Connect(function(Player, EffectName)
    --loop through players
    for _,v in pairs(game.Players:GetPlayers()) do
         if v ~= Player then
            --do effect
        end
    end
end)
3 Likes

I would use a simple for loop and then use GetPlayers. From there I would use another for loop to get players characters parts such as the torso. Then I would set the anchor of all them right there. Make sure it isn’t a local script

2 Likes

What do you mean by loops?

(30)

1 Like

for i,v in pairs(game.Players:GetPlayers()) do

1 Like
game.ReplicatedStorage.Event.OnServerEvent:Connect(function(Player, EffectName)
    for _,v in pairs(game.Players:GetPlayers()) do
         if v ~= Player then	
	game.Lighting.ColorCorrection.Saturation = -1
	game.Lighting.bruh.Saturation = -1
	wait(2)
	game.Lighting.bruh.Saturation = 0
	game.Lighting.ColorCorrection.Contrast = -2
			wait (3) 
			game.Lighting.ColorCorrection.Contrast = 0
			game.Lighting.ColorCorrection.Saturation = 0
	end
for i,v in pairs(game.Players:GetPlayers()) do
local humanoid = game.WaitForChild("Humanoid")
local Lighting = game.Lighting
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
game:GetService("Players")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = Humanoid:LoadAnimation(run)
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
	    if not gameProcessed then
				        if Input.KeyCode == Enum.KeyCode.F then
					    for _,v in pairs(game.Players:GetPlayers()) do
						         if v ~= Player then
							Player.Character.Humanoid.Anchored = true
							game.ReplicatedStorage.Event:FireServer(function(EffectName)
			runtrack:Play()
			workspace.Sound2:Play()
for i, v in pairs (game.Players:GetPlayers()) do
if v.Name ~= "Someone" then 
					v.Character.HumanoidRootPart.Anchored = true
					Lighting.ColorCorrection.Saturation = -1
					Lighting.bruh.Saturation = -1
					wait(2)
					Lighting.ColorCorrection.Contrast = 1
									Lighting.ColorCorrection.Saturation = 0
									Lighting.bruh.Saturation = 0
					wait(3)
					Lighting.ColorCorrection.Contrast = 0
					Lighting.bruh.Saturation = 0
					for i, v in pairs (game.Players:GetPlayers()) do
if v.Name ~= "Someone" then 
					v.Character.HumanoidRootPart.Anchored = false
				
				end
			end
		end
	end
		end)	
	end
	end
		end
		
		end
	end)
		end
	end
	end)


So I tried this. Any mistakes that i’ve made?
(This is not in a local script)

I have also made a seperate Local Script to unanchor the person using it.

local Lighting = game.Lighting
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
game:GetService("Players")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = Humanoid:LoadAnimation(run)
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
	    if not gameProcessed then
		        if Input.KeyCode == Enum.KeyCode.F then
			runtrack:Play()
			
			workspace.Sound2:Play()
for i, v in pairs (game.Players:GetPlayers()) do
if v.Name ~= game.Players.LocalPlayer then -- The person that's immune 
					v.Character.HumanoidRootPart.Anchored = false
				
				end
			end
		end
	end
		end)

Handle everything on the server, but input on the client. If you know what FilteringEnabled is anchoring the players on the client will only show for you and not everyone else in the game.
edit:

game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
	if gameProcessed then return end--If they are chatting or doing some other things, don't continue
    if input.KeyCode == Enum.KeyCode.F then        
        game.ReplicatedStorage.Event:FireServer()--Telling the server to freeze everybody
    end
end)

What do you mean? Could you put it in my script or show a better example?

1 Like

Read up on FilteringEnabled. There is a lot of articles and info about it.
I’ll put the basic idea of what you should do.

--Local Script
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
	if gameProcessed then return end--If they are chatting or doing some other things, don't continue
    if input.KeyCode == Enum.KeyCode.F then        
        game.ReplicatedStorage.Event:FireServer()--Telling the server to freeze everybody
    end
end)
--Server Script
game.ReplicatedStorage.Event.OnServerEvent:Connect(function(playerWhoFired) -- the .OnServerEvent() event automatically puts the player who fired the event as the first parameter
    for i, player in pairs(game.Players:GetPlayers()) do --Looping through every player in the game.
        if player ~= playerWhoFired then -- The person that fired event wont get frozen
		    player.Character.HumanoidRootPart.Anchored = true --Freezing/Anchoring the player so they can't move.
	    end
    end
end)

Things you should know to be able to do this are:
-Remote Events
-Filtering Enabled
-In Pairs loop
-UserInputService

Hey,
what you could do is instead of anchoring, set their walk speed and jump power to 0 (making it so they cant move).

Here’s what it will look like:

local Lighting = game.Lighting
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
game:GetService("Players")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = Humanoid:LoadAnimation(run)
local remoteevent = -- Reference your remote here

-- Local Script
game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
    if not gameProcessed then
        if Input.KeyCode == Enum.KeyCode.F then
            runtrack:Play()
            workspace.Sound2:Play()
            remoteevent:FireServer()
        end
    end
end)

-- Server Script
lolca remoteevent = -- Reference your remote here again

remoteevent.OnServerEvent:Connect(function(player)
    for i,v in pairs(game:GetService("Players"):GetChildren()) do
        if v.Name ~= player.Name then
            -- Anchor/set walkspeed and jump power to 0
        end
    end
end)

Also, it may not work. If you get any errors, let me know and I’ll be more happy to help you out. :slight_smile:

Setting their walkspeed to 0 wouldn’t be a full time stop. If someone was jumping and someone time stopped, they would just fall down. If you anchored them, they would be froze in the air.

1 Like

Right, my bad. Forgot about that :slight_smile:

1 Like

Localscript:

local Lighting = game.Lighting
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
game:GetService("Players")
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://5458518027"
local runtrack = Humanoid:LoadAnimation(run)
local remoteevent = game.ReplicatedStorage.Event

game:GetService("UserInputService").InputBegan:Connect(function(Input,gameProcessed)
	if gameProcessed then return end--If they are chatting or doing some other things, don't continue
    if Input.KeyCode == Enum.KeyCode.F then        
		        remoteevent:FireServer("playerwhoFired")--Telling the server to freeze everybody
		runtrack:Play()
		
    end
end)

Serverscript:

game.ReplicatedStorage.Event.OnServerEvent:Connect(function(playerWhoFired) 
    for i, player in pairs(game.Players:GetPlayers()) do 
        if player ~= playerWhoFired then -- 
			    player.Character.HumanoidRootPart.Anchored = true
			game.Workspace.Sound2:Play() 
			game.Lighting.ColorCorrection.Saturation = -1
			game.Lighting.ColorCorrection.Contrast = -2
			wait(5)
			game.Lighting.ColorCorrection.Contrast = 0
game.Lighting.ColorCorrection.Saturation = 0			
			
	    end
    end
end)

Apparently an infinite yield is also possible for WaitForChild(“Humanoid”)', according to the output. Any fix?

1 Like