I am working on a spell-type game where if you click, it fires an event to the server with your name and the position of where you clicked. (position of mouse.hit is a). Then, the server script that gets the remote makes a ray that zigzags to where you clicked. My only issue is that it is going too slow. Is there anyway to make the ray go faster? Here is my script:

game.ReplicatedStorage.flipp.OnServerEvent:Connect(function(player, name, a)
    
local animation = game.Players:FindFirstChild(name).Character.Humanoid:LoadAnimation(game.Workspace:FindFirstChild(name).Wand.Animation)
        animation:Play()
local characterr = game.Workspace:FindFirstChild(name)
lol = Instance.new("Sound")
lol.Parent =  game.Workspace:FindFirstChild(name).Wand.Tip
lol.SoundId = "rbxassetid://216866651"
lol.MaxDistance = 100
lol.EmitterSize = 100
lol:Play()

wait(.3)

--local ray = Ray.new(game.Workspace:FindFirstChild(name).Wand.Tip.Position(a - game.Workspace:FindFirstChild(name).Wand.Tip.Position).Unit * 750)

local character = game.Workspace:FindFirstChild(name)
local origin = character.Wand.Tip.Position


local ray = Ray.new(origin, (a - origin).Unit * 750)
local studsUporDown = 0.25
local timeTillNext = 0.025
local segmentLength = 2
local damageAmount = 10
local part = game.ReplicatedStorage.flip:Clone()
part.Parent = workspace
studsUporDown = studsUporDown * 100

local function entropy()
    local x = math.random(-studsUporDown,studsUporDown) / 100
    local y = math.random(-studsUporDown,studsUporDown) / 100
    local z = math.random(-studsUporDown,studsUporDown) / 100
  return Vector3.new(x, y, z)
end
spawn(function()
    for i = 0, 750, segmentLength do
        local Next = ray.Origin + i * ray.Direction.Unit + entropy()
    local damageRay = Ray.new(part.Position, (Next - part.Position).Unit * segmentLength)
part.CFrame = CFrame.new(Next)
    local hit, End = workspace:FindPartOnRay(damageRay, character, false, true)
if hit and hit ~= part then
        print(hit)
            local burn = game.ReplicatedStorage.fliph

part:Destroy()
        part.CFrame = CFrame.new(End)
        local hum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
        if hum then
            hum:TakeDamage(damageAmount)
            spawn(function()


            end)
    else
	wait(.01)
    local burnHit = burn:Clone()
    burnHit.CFrame = CFrame.new(End)
    burnHit.Parent = workspace
 local hit, pos, normal = game.Workspace:FindPartOnRay(ray)
burnHit.CFrame = CFrame.new(pos, pos + normal) * CFrame.Angles(-math.pi/2,0,0)



        end
break
    end
        wait(timeTillNext)
    end
end)
end)

ANYTHING HELPS.

ex of how slow it is: https://gyazo.com/f787086bfab527fb29a78bb9aee3c5d9

2 comments

0

You should consider ray casting on the client instead, just so it's immediate. You can then send info from the client to the server, and the server can do checks to make sure everything is legal.

0

Wait at least 3 days before re-posting a question if no one has answered yet.