Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What's a more efficient way to do this?

It's just hovering a block above the player's head but it's really choppy, how do I smooth it out?

local thng = game.ServerStorage.ioo:Clone()

game.Players.PlayerAdded:connect(function(plr)
	thng.Parent = workspace
	thng.Name = plr.Name.."'s ioo"
	thng.CanCollide = false
	local char = workspace:WaitForChild(plr.Name)
	while wait() do
		thng.Position = char.Head.Position + Vector3.new(0, 5, 0)
	end
end)

5 comments

0

is this FE?

0

no

0

Oh, then just use RunService

0

Use a weld

0

To make it more efficient, I'd: 1. Instead of just line 1 getting 'ioo' automatically, why not use 'WaitForChild' just incase if it isn't existant in time of execution? 2. I wouldn't use line 7 either; I'd just use 'plr.Character' :P 3. I'd recommend using 'CharacterAdded' too, because if the player resets, they'll lose 'ioo' w/ your current code. ;-;

3 answers

local thng = game.ServerStorage.ioo:Clone()

game.Players.PlayerAdded:connect(function(plr)
    thng.Parent = workspace
    thng.Name = plr.Name.."'s ioo"
    thng.CanCollide = false
    local char = workspace:WaitForChild(plr.Name)
    while wait() do
        thng.Position = char.Head.Position + Vector3.new(0, 5, 0)
    end
end)

wait() is about 1/30th of a second.

game:GetService("RunService").RenderStepped:wait()

RenderStepped is about 1/60th of a second, so just add that into it.

local thng = game.ServerStorage.ioo:Clone()

game.Players.PlayerAdded:connect(function(plr)
    thng.Parent = workspace
    thng.Name = plr.Name.."'s ioo"
    thng.CanCollide = false
    local char = workspace:WaitForChild(plr.Name)
    while game:GetService("RunService").RenderStepped:wait() do
        thng.Position = char.Head.Position + Vector3.new(0, 5, 0)
    end
end)

Actually, I say the best way to do it is using heartbeat, heartbeat will fire about 40 times per second, ensuring that you get the right CFrame;

first we have to get the runservice;

local rs = get:GetService("RunService").Heartbeat

then, if you wanted you could have it followed by the playeradded function,

local rs = game:GetService("RunService").Heartbeat
local thng = game.ServerStorage.ioo:Clone()

game.Players.PlayerAdded:connect(function(plr)
    thng.Parent = workspace
    thng.Name = plr.Name.."'s ioo"
    thng.CanCollide = false
    local char = workspace:WaitForChild(plr.Name)
   rs:connect(function()
        thng.Position = char.Head.Position + Vector3.new(0, 5, 0)
    end)
end)


3 comments

0

HeartBeat fires for the players FPS, if they have a bad computer, it might not work right

0

@theCJarmy7 It's the same w/ RenderStepped too; if the player's actual FPS lowers, so does the amount of times RenderStepped does too. :P

0

Really? The wiki must be forgetting things...

You could use RunService RenderStepped, more specifically :BindToRenderStep(). This is an example of how you can implement this into your script. Or you can just use a weld. You must use :WaitForChild for this so I already changed it for you.

local thng = game.ServerStorage:WaitForChlid('ioo'):Clone()

game.RunService:BindToRenderStep("PutAnythingHere", Enum.RenderPriority.Last.Value, function()
    thng.Parent = workspace
    thng.Name = plr.Name.."'s ioo"
    thng.CanCollide = false
    local char = workspace:WaitForChild(plr.Name)
    thng.Position = char.Head.Position + Vector3.new(0, 5, 0)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.