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

Why the coin floats above the head?

Asked by
yoavstr 52
5 years ago

I made a coin collecting system (there are coins around the map and the players pick them up to get cash). I've enabled Filtering so when some take the coin it will disappear only for him. To make it look a bit better I use a script that makes it float. My problem is when player 1 goes to a coin that is on player's 2 client the coin floats above player 1 head for player 2. I tried to disable the float script and it worked but I want to keep it.

Float script:

local num = script.Parent.num.Value
local coin = game.Workspace:WaitForChild("Coins"):WaitForChild("Coin"..num)

local coinPosition = coin.Position

while true do
    wait(0.1)
    for i = 1, 5 do
        wait(0.1)
        coin.Position = coin.Position + Vector3.new(0,i/40,0)
    end
    for i = 4, 1, -1 do
        wait(0.1)
        coin.Position = coin.Position + Vector3.new(0,i/40,0)
    end
    wait(0.1)
    for i = 1, 5 do
        wait(0.1)
        coin.Position = coin.Position + Vector3.new(0,-i/40,0)
    end
    for i = 4, 1, -1 do
        wait(0.1)
        coin.Position = coin.Position + Vector3.new(0,-i/40,0)
    end
    coin.Position = coinPosition
end

the script is not mine.

0
You should use CFrame instead of Position NopeUsername 0 — 5y
0
I'd put that for loop its own function so it would be easier to make calls upon as well. T0XN 276 — 5y

1 answer

Log in to vote
0
Answered by
Xiousa 156
5 years ago

Position automatically moves the instance upwards to avoid any collisions. Using CFrame, however, will not, and will keep the instance in the same spot.

local num = script.Parent.num.Value
local coin = game.Workspace:WaitForChild("Coins"):WaitForChild("Coin"..num)

local coinPosition = coin.CFrame

while true do
    wait(0.1)
    for i = 1, 5 do
        wait(0.1)
        coin.CFrame = coin.CFrame * CFrame.new(0,i/40,0)
    end
    for i = 4, 1, -1 do
        wait(0.1)
        coin.CFrame = coin.CFrame * CFrame.new(0,i/40,0)
    end
    wait(0.1)
    for i = 1, 5 do
        wait(0.1)
        coin.CFrame = coin.CFrame * CFrame.new(0,-i/40,0)
    end
    for i = 4, 1, -1 do
        wait(0.1)
        coin.CFrame = coin.CFrame * CFrame.new(0,-i/40,0)
    end
    coin.CFrame = coinPosition
end
Ad

Answer this question