Well, I’m trying to get the red object to be thrown forward until it touches the green object, when that happens, the red object must stop moving immediately.
The red object is taking too long to stop moving, and I need the object to stop before crossing, because I’m trying to create a spell collision with it.
local FX = workspace:WaitForChild("FX")
local rStorage = game:GetService("ReplicatedStorage")
local rEvent = rStorage.Events:WaitForChild("Projectile")
local char = workspace:WaitForChild(plr.Name)
local hum = char:WaitForChild("HumanoidRootPart")
local x = Instance.new("Part", FX)
x.Name = "Projectile"
x.Anchored = false
x.CanCollide = false
x.BrickColor = BrickColor.new("Really red")
x.Material = "Neon"
x.Shape = "Ball"
x.Size = Vector3.new(3,3,3)
x.CFrame = hum.CFrame * CFrame.new(0,0,-3)
local bv = Instance.new("BodyVelocity", x)
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = hum.CFrame.lookVector * 100
if hit.Name == "Barrier" then
bv.Velocity = Vector3.new()
Thank you for your attention!
Do you mean WaitForChild:(plr.Character)?
Both work. The script is not giving an error, it is just not having the expected result…
What are you exactly trying to get in result?
I would like the projectile to stop moving as soon as it touches the barrier, but at the moment it’s moving a little bit from the position it should stop
Is the spell moving fast? The physics updates at 60 fps, It might be going so fast that it goes through the block or the update happened and the spell is inside the block
Try using raycast. You can make it so that collision occurs when raycast’s length goes under a certain threshold, e.g 0.1 studs.
Never use Touched for this type of things, you can use Ray Cast.
Try setting the networkownership of the parts to ‘nil’, this sets it automatically to the server. I hope this helps your problem.
Maybe I’m a little late but use RunService.HeartBeat in order to
- move the projectile
- send several raycasts to detect if the projectile hit something.
Neither body velocities and tween service are efficient for making projectiles.