I have a script that where ever you click, a spell will fly there. If it hits a object with a humanoid, it will damage it and stun it. If it does not, then it will make a burn mark on where it is hit. My problem is that if a burn mark is made anywhere except the floor, it will stick out. For example, this is it on the floor:
https://gyazo.com/98ad24caa7f69301887ae4fa703ff9b9
But if I shoot it at a wall, this is how it will look:
https://gyazo.com/5a91e361458701f94115330e8ef670d5
Does anyone have any ideas how to make it rotate so it looks like it does on the floor? Here is the script. If you have any questions, comment them!
"a" is mouse.hit that I got from a local script
hit is the burn mark
game.ReplicatedStorage.stupefyy.OnServerEvent:Connect(function(player, name, a)
local animation = game.Players:FindFirstChild(name).Character.Humanoid:LoadAnimation(game.Workspace:FindFirstChild(name).Wand.Animation)
animation: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.stup:Clone()
part.Parent = workspace
studsUporDown = studsUporDown * 100
local function entropy()
local x = math.random(-studsUporDown,studsUporDown) / 50
local y = math.random(-studsUporDown,studsUporDown) / 50
local z = math.random(-studsUporDown,studsUporDown) / 50
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.hit
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()
hum.PlatformStand = true
wait(10)
hum.PlatformStand = false
end)
else
local burnHit = burn:Clone()
burnHit.CFrame = CFrame.new(End)
burnHit.Parent = workspace
end
break
end
wait(timeTillNext)
end
end)
end)

3 comments
omg xD
what
I would use surface normals, they are one return value of FindPartOnRay https://www.robloxdev.com/api-reference/function/Workspace/FindPartOnRay