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

What's a more efficient way to do this?

Asked by
wackem 50
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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)
0
is this FE? theCJarmy7 1293 — 8y
0
no wackem 50 — 8y
0
Oh, then just use RunService theCJarmy7 1293 — 8y
0
Use a weld lightpower26 399 — 8y
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. ;-; TheeDeathCaster 2368 — 8y

3 answers

Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
8 years ago
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)

Ad
Log in to vote
0
Answered by 8 years ago

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)


0
HeartBeat fires for the players FPS, if they have a bad computer, it might not work right theCJarmy7 1293 — 8y
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 TheeDeathCaster 2368 — 8y
0
Really? The wiki must be forgetting things... theCJarmy7 1293 — 8y
Log in to vote
0
Answered by 8 years ago

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)

Answer this question