I took Roblox' basic coin and instead of it just disappearing when I collect it, I want it to slowly fade out and move toward the player, so it looks smoother. My plan was for it to move 50 times during a second, that should be a smooth movement. The fading works fine, but the movement does nothing and I don't know what else to do.
amnt = 1 --how much you get for it Blox = script.Parent function onTouched(part) Blox = script.Parent local h = part.Parent:findFirstChild("Humanoid") if (h~=nil) then local thisplr = game.Players:findFirstChild(h.Parent.Name) if (thisplr~=nil) then local stats = thisplr:findFirstChild("leaderstats") if (stats~=nil) then local score = stats:findFirstChild("Points") if (score~=nil) then score.Value = score.Value + amnt end end end local t = part.Parent:findFirstChild("Torso") local i = 1 while i < 510 do local dist = (t.Position-Blox.Position) Blox.Position = Blox.Position + Vector3.new(dist/50) Blox.CFrame=Blox.CFrame + Vector3.new(dist) Blox.Transparency = Blox.Transparency+0.01 wait(0.02) i = i + 1 end Blox:Destroy() end end Blox.Touched:connect(onTouched)
Aha i think i see your problem. It is to do with lines 22-23 with the Vector3.new you have.
You have only placed in one value instead of 3.
I make this mistake all the time and it is simply because i make a variable including the 3 values and thinking lua will automatically detect that it is 3 values but this is wrong. What'll you will have to do is find a way of obtaining all 3 values for your Parts Vector3.
This is due to deprecated code.
In lines 5, 7, 9, 11, 18, you’re using findFirstChild
, which is deprecated.Switch to FindFirstChild
.
And on lines 6, 8, 10, 12, you are wrapping your if statements in brackets. Brackets are math exclusive, so remove them. And remove the ~= nil
as it is redundant and only extends your if statement.
You should also switch to Connect
, as ROBLOX may be removing connect
soon.