why does it not work i tried everything on my own end but still cannot work
it doesnt print worked
-- services
local RunService = game:GetService("RunService")
while true do
RunService.Stepped:wait()
print("worked")
-- iterate through all the players and check if there distance to the magnitude is more then 150 or something
for _, Player in pairs(game.Players:GetPlayers()) do
if Player.Character then
if Player.Character:FindFirstChild("Humanoid") and Player.Character:FindFirstChild("HumanoidRootPart") then
local character = Player.Character
local HumanoidRootPart = character.HumanoidRootPart
local Baseplate = workspace.Baseplate
HumanoidRootPart:GetPropertyChangedSignal("Position"):Connect(function()
local Distance = (HumanoidRootPart.Position - Baseplate.Position).Magnitude
local OldPosition = HumanoidRootPart.CFrame
if Distance > 130 then
HumanoidRootPart.CFrame = OldPosition
end
end)
end
end
end
end
local LastData = {}
for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
if Player.Character then
if Player.Character:FindFirstChildOfClass("Humanoid") and Player.Character:FindFirstChild("HumanoidRootPart") then
local character = Player.Character
local HumanoidRootPart = character.HumanoidRootPart
local Baseplate = workspace.Baseplate
if not LastData[Player.UserId] then
LastData[Player.UserId] = {
CFrame = Player.Character.HumanoidRootPart.CFrame,
Tick = tick(),
}
end
if (LastData[Player.UserId].Position - Player.Character.HumanoidRootPart.Position).Magnitude > Player.Character:FindFirstChildOfClass("Humanoid").WalkSpeed + 1 * (tick() - LastData[Player.UserId].Tick) then
Player.Character:FindFirstChildWhichIsA("Humanoid").RootPart.CFrame = LastData[Player.UserId].CFrame
else
LastData[Player.UserId] = {
CFrame = Player.Character.HumanoidRootPart.CFrame,
Tick = tick(),
}
end
end
end
end
and i am trying to make a duplicate of it and make it like if its too far from the baseplate it would instantly kick you or move back
ok i used another method that doesnt even work its like the other code i gave
-- iterate through all the players and check if there distance to the magnitude is more then 150 or something
for _, Player in pairs(game.Players:GetPlayers()) do
if Player.Character then
if Player.Character:FindFirstChildOfClass("Humanoid") and Player.Character:FindFirstChild("HumanoidRootPart") then
print("worked")
local character = Player.Character
local Humanoid = character.Humanoid
local HumanoidRootPart = character.HumanoidRootPart
local Baseplate = workspace.Baseplate
local OldPos = HumanoidRootPart.CFrame
if not JumpData[Player.UserId] then
JumpData[Player.UserId] = {
CFrame = HumanoidRootPart.CFrame;
Tick = tick()
}
end
if (JumpData[Player.UserId].Position - Baseplate.Position).Magnitude >= 130 * (tick() - JumpData[Player.UserId].Tick) then
HumanoidRootPart.CFrame = OldPos
else
JumpData[Player.UserId] = {
CFrame = HumanoidRootPart.CFrame;
Tick = tick()
}
end
end
end
end
no method of getting magnitude its still doesnt work i would have to get a better method i dont think that raycasting is possible unless i just make a part that kicks them
I don’t believe using RunService’s RenderStepped event is a good idea, if you aren’t making any expensive actions like customizing or changing how the camera works in your game. Instead, use the Heartbeat event. It can also fire every 1/60 of a frame, the same like RenderStepped, and it also returns what we call deltatime.
If you don’t know about it, you can check about it here.
But hey, it’s Roblox! Hence the title Powering Imagination that they mostly encourage in Roblox, so you do you! It’s your game, almost anything is possible. Go get 'em tiger!
It doesn’t only work on client, all of the RunService events are functional on both sides. They are all three the same but only has a difference in a small marginal of time. It’s all in the task scheduler.