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

Script does not care about variable speed?

So i made a game and i need to use this script:

Pos = script.Parent.Position
Timer = 0
Spd = 10
Radius = 1
while true do
X = Pos.X+Radius*math.cos(Timer-1*Spd*15)*1
Z = Pos.Y+Radius*math.cos(Timer-11*Spd*15)*1
script.Parent.Position = Vector3.new(X,Pos.Y,Z)
Timer = Timer + 0.1
wait(0.1)
end

Basically it makes a star particle emitter move like a circle and make a knock-out effect. But the script doesen't care about the Spd (Speed) variable. As example, when i change the speed to 100, It wont have an effect. Help?

1 answer

✓ Accepted answer

You want to have timer change by speed to get the result you want. Otherwise, by multiplying the argument of math.cos by speed, you simply change the starting position of the cosine graph (try twiddling around with (y = cos(x - 1 * d * 15) in desmos. You ideally want a script that looks like this.

Pos = script.Parent.Position
Timer = 0
Spd = 10
Radius = 1
while true do
	X = Pos.X+Radius*math.cos(Timer-1*Spd*15) -- no clue why there was a * 1 here
	Z = Pos.Y+Radius*math.cos(Timer-11*Spd*15)
	script.Parent.Position = Vector3.new(X,Pos.Y,Z)
	Timer = Timer + Spd/10
	wait(0.1)
end

Furthermore, based on what you described, this script should be in a local script. Thus to update the animation every frame to make it look way smoother, use https://developer.roblox.com/en-us/api-reference/event/RunService/Heartbeat instead of wait(0.1)

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