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.
01 | amnt = 1 --how much you get for it |
02 | Blox = script.Parent |
03 | function onTouched(part) |
04 | Blox = script.Parent |
05 | local h = part.Parent:findFirstChild( "Humanoid" ) |
06 | if (h~ = nil ) then |
07 | local thisplr = game.Players:findFirstChild(h.Parent.Name) |
08 | if (thisplr~ = nil ) then |
09 | local stats = thisplr:findFirstChild( "leaderstats" ) |
10 | if (stats~ = nil ) then |
11 | local score = stats:findFirstChild( "Points" ) |
12 | if (score~ = nil ) then |
13 | score.Value = score.Value + amnt |
14 | end |
15 | end |
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.