Hi, first of all, sorry if I wrote the question incorrectly.So basically my other script manage to shoot a bullet, that's being cloned.
** So the problem is:**
-Everytime I press leftclick, a remoteEvent triggers, and a bullet is moving forward for a time, but
it gets more, and more far away, why?
What i'm trying to get:
-Evertyime I shoot, a cloned bullet is moving forward like a 100 stud, or something.
here's my first script, which needs fixing:
script.Parent.fire.OnServerEvent:Connect(function(player) for i = 1,10 do wait(0.5) script.Parent.Bullet.Position = script.Parent.Bullet.Position + Vector3.new(0.5, 0, 0) end end)
And here's the other one which is, in my opinion is good( if it helps):
local fire = script.Parent:WaitForChild('fire') fire.OnServerEvent:Connect(function(player) local clone = script.Parent.Bullet:Clone() clone.Parent = workspace clone.Orientation = script.Parent.Handle.Orientation + Vector3.new(0, 90, 0) clone.Transparency = 0 script.Parent.Lightgive.PointLight.Enabled = true wait(0.1) script.Parent.Lightgive.PointLight.Enabled = false end)
Thanks for reading!
script.Parent.Bullet.Position = script.Parent.Bullet.Position + Vector3.new(0.5, 0, 0)
Here you are changing the position of the bullet, but this is not the right bullet.
local clone = script.Parent.Bullet:Clone() clone.Parent = workspace
In this code, you clone a bullet and parent it to workspace. But unless script.Parent is workspace itself, then the bullet positioning script is referring to the wrong bullet. Even if it was, these bullets aren't named differently and the script won't be able to differentiate between different bullets.
If I were you, I would combine both scripts into one:
local fire = script.Parent:WaitForChild('fire') local function movebullet(bullet) for i = 1, 10 do task.wait(0.5) bullet.Position = bullet.Position + Vector3.new(0.5, 0, 0) end end fire.OnServerEvent:Connect(function(player) local clone = script.Parent.Bullet:Clone() clone.Orientation = script.Parent.Handle.Orientation + Vector3.new(0, 90, 0) clone.Transparency = 0 script.Parent.Lightgive.PointLight.Enabled = true clone.Parent = workspace task.spawn(function() task.wait(0.1) script.Parent.Lightgive.PointLight.Enabled = false end) movebullet(clone) end)
Now, the script will be able to move the right bullet.