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

Why the coin floats above the head?

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.

2 comments

0

You should use CFrame instead of Position

0

I'd put that for loop its own function so it would be easier to make calls upon as well.

1 answer

✓ Accepted answer

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

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