Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm making a "Time Stop", but it only works in Studio and not in-game, is there a way to fix this?

Asked by 6 years ago
Edited 6 years ago

I am making something where if you press Q, anyone within 200 studs will stop moving completely, but this won't work in-game, only in Studio.

Here's the code I used:

01game.Players.PlayerAdded:Connect(function(player)
02    wait(.1)
03hi = player.Name
04 
05print(hi)
06local player = game.Players[hi]
07player:GetMouse().KeyDown:Connect(function(k)
08    if k == "q" and player.Name == "bearpro2" then
09        for i, v in pairs(workspace:GetChildren()) do
10            if v:FindFirstChild("Humanoid") then
11                if v.Name == player.Name then
12                else
13                    if (v.Torso.Position -  player.Character.Torso.Position).Magnitude <= 200 then
14                        v.Torso.Anchored = true
15                        v["Right Leg"].Anchored = true
View all 26 lines...
0
Maybe you didn't upload these? MEndermanM 73 — 6y
0
I thought that at first too, but then I published the game and it still didn't work. bearpro2 6 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

So a few things, you shouldn't be using KeyDown as it is deprecated, so I would recommend using the UserInputService. I also don't think you can get a player's keyboard inputs from the server.

A better way to set this up would be to put this code in a local script, and use a remote event

Create a RemoteEvent in Replicated Storage, name it "FreezeEvent" for now, then create a Local Script in StarterPack with the following code

01local player = game:GetService("Players").LocalPlayer
02local char = player.CharacterAdded:wait() -- Waits for the character
03 
04local UIS = game:GetService("UserInputService")
05local RS = game:GetService("ReplicatedStorage")
06local freeze = RS:WaitForChild("FreezeEvent") -- You can name this remote event whatever you want
07 
08UIS.InputBegan:connect(function(input,gpe) -- InputBegan event takes 2 parameters, the InputObject and GPE(Game Processed Event)
09    if not gpe then -- Makes sure you can't use this ability while typing.
10        if input.KeyCode == Enum.KeyCode.Q and player.Name == "bearpro2" then -- You can change the controls to whatever
11            freeze:FireServer() -- Calls the server via the RemoteEvent
12        end
13    end
14end)

Then create a Script in ServerScriptService with the following code

01local UIS = game:GetService("UserInputService")
02local RS = game:GetService("ReplicatedStorage")
03local freeze = RS:WaitForChild("FreezeEvent") -- You can name this remote event whatever you want.
04 
05-- Listens for the RemoteEvent to be called
06freeze.OnServerEvent:connect(function(player) -- Remote events always return the player who sent the request.
07    for i,v in pairs(workspace:GetChildren()) do
08        if v:FindFirstChild("Humanoid") and v ~= player.Character  then
09            if (v.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude <= 200 then -- use HumanoidRootPart so it's compatible with both R6 and R15
10                for i,child in pairs(v:GetChildren()) do
11                    -- BasePart includes both Parts and MeshParts
12                    if child:IsA("BasePart") then -- Loops through all the parts inside the model instead of looking for specific parts.
13                        child.Anchored = true -- Anchors it.
14                    end
15                end
16            end
17        end
18    end
19end)

lol remember to mark me as the answer if this helps you btw

0
Thank you! I only looked at this answer today because I was occupied, so sorry for not marking the answer earlier. Thanks though, this was amazing bearpro2 6 — 6y
Ad

Answer this question