You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
So I’ve made a fire ball Attack and i want when it touches a part that part go back like umm knockback but for parts -
What is the issue? Include screenshots / videos if possible!
I’ve got it kinda working the Part moves but in the wrong direction.
they come to the player’s character instead of going the away from it.
here’s a video for better explaination:
robloxapp-20220501-0532360
I have also a problem with raycasting but idk if i should put it here with this topic
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
So i tried to make the values negative but it didn’t work. I switched the first Vector inCFrame.lookAt
with the second Vector tbh i dont even know what im doing now
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
so umm here is the Script if it going to help
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
local D = game:GetService("Debris")
local event = RS.Fireball
local Cooldown = 2.5
local debounce = {}
local hitBox = script.HitBox
local Particlesfolder = script.Particles
local HitFX = script.HitEffect
local ShootAnimationId = 9496919137
local function PlayAnimation(char, Id)
local h = char:WaitForChild('Humanoid')
local animator = h:WaitForChild("Animator")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"..Id
local AnimationTrack = animator:LoadAnimation(Animation)
AnimationTrack:Play()
AnimationTrack:GetMarkerReachedSignal("End"):Connect(function()
print("End of the animation")
end)
end
local function ServerReceived(player, unitRay)
if table.find(debounce, player.UserId) ~= nil then
print('Under debounce')
else
local params = RaycastParams.new()
params.FilterDescendantsInstances = {player.Character,workspace.Baseplate}
params.FilterType = Enum.RaycastFilterType.Blacklist
local raycastresults = workspace:Raycast(unitRay.Origin,unitRay.Direction*500,params)
print("Server received")
if raycastresults then
print(raycastresults.Instance.Name)
print(raycastresults.Position)
--Visualising the raycast
--local distance = (unitRay.Origin - raycastresults.Position).Magnitude
--local p = Instance.new("Part",workspace)
--p.Color = Color3.fromRGB(255,85,0)
--p.Material = "Neon"
--p.Transparency = .3
--p.Anchored = true
--p.CanCollide = false
--p.Size = Vector3.new(0.1, 0.1, distance)
--p.CFrame = CFrame.lookAt(unitRay.Origin, raycastresults.Position)*CFrame.new(0, 0, -distance/2)
local Char = player.Character
local newHitBox = hitBox:Clone()
local pos = raycastresults.Position
local CF = Char.PrimaryPart.CFrame * CFrame.new(0,0,-4)
PlayAnimation(Char, ShootAnimationId)
event:FireAllClients(CF,pos)
table.insert(debounce, player.UserId)
newHitBox.CFrame = CF
newHitBox.Parent = workspace
newHitBox.Transparency = 1
D:AddItem(newHitBox, 5)
TS:Create(
newHitBox,
TweenInfo.new(1),
{Position = pos}
):Play()
newHitBox.Touched:Connect(function(hit)
if not hit:IsDescendantOf(Char) then
local h = hit.Parent:FindFirstChild("Humanoid")
----------------------------//This is where i have the problem\\------------------------------------
if not h and hit.Name~="Baseplate" then
print("Humanoid not found")
local ranNumber = math.random(5,30)
local distance = (unitRay.Origin - raycastresults.Position).Magnitude
TS:Create(
hit,
TweenInfo.new(1),
{CFrame = CFrame.lookAt((CFrame.new(raycastresults.Position)*CFrame.new(0,0,5).Position),unitRay.Origin)*CFrame.new(0, 0, -distance/2)}
):Play()
end
--------------------------------------------------------------------------------------------------------------
if h then
if h:FindFirstChild(player.Name.."fireBallDebounce") then
print("already touched")
else
print(hit.Name)
print("Hit")
local NewHitFX = HitFX:Clone()
NewHitFX.CFrame = hit.CFrame
NewHitFX.Parent = workspace
D:AddItem(NewHitFX, .2)
h:TakeDamage(5)
local dbValue = Instance.new("BoolValue")
dbValue.Name = player.Name.."fireBallDebounce"
dbValue.Parent = h
D:AddItem(dbValue,2)
for i, v in pairs(Particlesfolder:GetDescendants()) do
local ParticlesClone = v:Clone()
ParticlesClone.Parent = hit
D:AddItem(ParticlesClone, .5)
end
--KnockBack
local knockbackAnimationPt1 = 9512211627
local knockbackAnimationPt2 = 9512264719
PlayAnimation(hit.Parent,knockbackAnimationPt1)
PlayAnimation(h.Parent,knockbackAnimationPt2)
for i, v in pairs(hit.Parent:GetDescendants())do
if v:IsA("Attachemrnt") then
return
else
local ranNumber = math.random(5,30)
local CF = v.CFrame * CFrame.new(0,0,ranNumber)
TS:Create(
v,
TweenInfo.new(1),
{CFrame = CF}
):Play()
end
end
end
end
end
end)
wait(1)
debounce[table.find(debounce, player.UserId)] = nil
else
print("Nothing was found when raycasting")
end
end
end
event.OnServerEvent:Connect(ServerReceived)