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

How to make a collectible following the player?

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)

2 comments

0

ROBLOX's servers operate at 30fps/ticks/whatever, meaning moving 50 times per second is impossible.

0

I'll probably switch it to 25 times a second, thank you for letting me know this.

2 answers

✓ Accepted answer

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.

2 comments

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.

0

Sounds good. Glad i could help

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.

6 comments

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.

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?

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.

0

How many times must we argue for something you started? Stop harassing me!

0

You are spreading false information which is likely to confuse users.

0

No it isn’t, it does the opposite. It will prevent errors from future removal of these deprecated items.

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