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

How to make a collectible following the player?

Asked by 6 years ago

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)
0
ROBLOX's servers operate at 30fps/ticks/whatever, meaning moving 50 times per second is impossible. fredfishy 833 — 6y
0
I'll probably switch it to 25 times a second, thank you for letting me know this. tygerupercut3 68 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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.

0
Thank you so much, this makes so much sense now. I split dist into distx, disty, and distz and used them separately, and it works. Apparently I have some deprecated terms in the other code also. tygerupercut3 68 — 6y
0
Sounds good. Glad i could help NoirPhoenix 148 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
I'm using some of Roblox' original code so a lot of the terms are old and deprecated, so I will change them. Thanks. tygerupercut3 68 — 6y
0
"This is due to deprecated code." - that's not how deprecated code works. "you are wrapping your if statements in brackets" - which is a totally valid thing to do. How many times must we dance this dance? fredfishy 833 — 6y
0
Also when I said "deprecated methods are planned to be removed" it was more of a general statement, rather than "ROBLOX is removing connect in the near future". The deprecation of "connect" is likely more of a coding style change as opposed to a traditional deprecation. fredfishy 833 — 6y
0
How many times must we argue for something you started? Stop harassing me! User#19524 175 — 6y
View all comments (2 more)
0
You are spreading false information which is likely to confuse users. fredfishy 833 — 6y
0
No it isn’t, it does the opposite. It will prevent errors from future removal of these deprecated items. User#19524 175 — 6y

Answer this question