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:

game.Players.PlayerAdded:Connect(function(player)
    wait(.1)
hi = player.Name

print(hi)
local player = game.Players[hi]
player:GetMouse().KeyDown:Connect(function(k)
    if k == "q" and player.Name == "bearpro2" then
        for i, v in pairs(workspace:GetChildren()) do
            if v:FindFirstChild("Humanoid") then
                if v.Name == player.Name then
                else
                    if (v.Torso.Position -  player.Character.Torso.Position).Magnitude <= 200 then
                        v.Torso.Anchored = true
                        v["Right Leg"].Anchored = true
                         v["Right Arm"].Anchored = true
                        v["Left Leg"].Anchored = true
                        v["Left Arm"].Anchored = true

                    end
                end
            end
        end
    end
end)
end)
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

local player = game:GetService("Players").LocalPlayer
local char = player.CharacterAdded:wait() -- Waits for the character

local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local freeze = RS:WaitForChild("FreezeEvent") -- You can name this remote event whatever you want

UIS.InputBegan:connect(function(input,gpe) -- InputBegan event takes 2 parameters, the InputObject and GPE(Game Processed Event) 
    if not gpe then -- Makes sure you can't use this ability while typing.
        if input.KeyCode == Enum.KeyCode.Q and player.Name == "bearpro2" then -- You can change the controls to whatever
            freeze:FireServer() -- Calls the server via the RemoteEvent
        end
    end
end)

Then create a Script in ServerScriptService with the following code

local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local freeze = RS:WaitForChild("FreezeEvent") -- You can name this remote event whatever you want.

-- Listens for the RemoteEvent to be called
freeze.OnServerEvent:connect(function(player) -- Remote events always return the player who sent the request.
    for i,v in pairs(workspace:GetChildren()) do
        if v:FindFirstChild("Humanoid") and v ~= player.Character  then
            if (v.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude <= 200 then -- use HumanoidRootPart so it's compatible with both R6 and R15
                for i,child in pairs(v:GetChildren()) do
                    -- BasePart includes both Parts and MeshParts
                    if child:IsA("BasePart") then -- Loops through all the parts inside the model instead of looking for specific parts.
                        child.Anchored = true -- Anchors it.
                    end
                end
            end
        end
    end 
end)

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