Tool = script.Parent Player = Tool.Parent.Parent Character = Player.Character Humanoid = Character.Humanoid root = Character.HumanoidRootPart Mouse = Player:GetMouse()
Tool.RemoteEvent.OnServerEvent:Connect(function(Player, mouseHit)
root.CFrame = CFrame.new(root.Position,root.Position + Vector3.new(mouseHit.lookVector.x, 0, mouseHit.lookVector.z)) --[[ 1st argument is position second argument is direction ( where it is is and where its going to look at]] local kiblast = Tool.Handle:clone() game.Debris:AddItem(kiblast, 2) kiblast.CFrame = Humanoid.Parent.RightHand.CFrame local v = Instance.new("BodyVelocity") v.Parent = kiblast v.velocity = mouseHit.lookVector * 90 v.MaxForce = Vector3.new(math.huge, math.huge, math.huge) kiblast.CanCollide = false kiblast.Parent = game.Workspace kiblast.Transparency = 0 kiblast.Touched:Connect(function(hit) local hum = hit.Parent:findFirstChild("Humanoid") if hum and hum ~= Humanoid then local explosion = Instance.new("Part") local Torso = hum.Torso explosion.Parent = game.Workspace explosion.Shape = "Ball" explosion.BrickColor = BrickColor.new("New Yeller") explosion.Material = "Neon" explosion.Size = Vector3.new(15, 15,15) explosion.CanCollide = false explosion.Position = Torso.Position explosion.Anchored = true for i = 0, 1, 0.02 do wait(0.01) explosion.Transparency = i end hum:TakeDamage(5) game.Debris:AddItem(explosion, .0000000000000000001) elseif hit.Anchored and hit.CanCollide == true then for i = 1,10 do local part = kiblast:clone() part.Size = Vector3.new(0.5 , .5, .5) part.CFrame = kiblast.CFrame part.Parent = game.Workspace part.BodyVelocity.Velocity = Vector3.new(math.random(-15,15), math.random(-15,15), math.random(-15,15)) * 5 --[[ without the times 50 it goes at a random speed i think --]] game.Debris:AddItem(part, 1) end end end)
end)
You need to add a debounce for your Touched function.
You made a few mistakes which I corrected. I haven't taken the time to test this script, but hopefully you can learn stuff from it.
Hope this works, any questions let me know in the comments.
local Tool = script.Parent local Player = Tool.Parent.Parent:IsA("Player") and Tool.Parent.Parent or game.Players:GetPlayerFromCharacter(Tool.Parent) local Character = Player.Character or Player.CharacterAdded:Wait() -- wait for character to load in if it hadn't already local Humanoid = Character:FindFirstChildWhichIsA("Humanoid") -- humanoid's name could change for some reason, let's just make sure we get it local root = Character.PrimaryPart -- the primary part for the character is the HumRootPart local Mouse = Player:GetMouse() -- this is fine Tool.RemoteEvent.OnServerEvent:Connect(function(Player, mouseHit) root.CFrame = CFrame.new(root.Position,root.Position + Vector3.new(mouseHit.lookVector.x, 0, mouseHit.lookVector.z)) --[[ 1st argument is position second argument is direction ( where it is is and where its going to look at]] local kiblast = Tool.Handle:Clone() game.Debris:AddItem(kiblast, 2) kiblast.CFrame = Humanoid.Parent.RightHand.CFrame local v = Instance.new("BodyVelocity") v.Parent = kiblast v.velocity = mouseHit.lookVector * 90 v.MaxForce = Vector3.new(math.huge, math.huge, math.huge) kiblast.CanCollide = false kiblast.Parent = game.Workspace kiblast.Transparency = 0 local connection -- make this accessible in the future by defining the variable here connection = kiblast.Touched:Connect(function(hit) connection:Disconnect() -- get rid of future touched connections local hum = hit.Parent:FindFirstChild("Humanoid") if (hum and hum ~= Humanoid) then local explosion = Instance.new("Part") local Torso = hum.Parent:FindFirstChild("Torso") or hum.Parent:FindFirstChild("UpperTorso") -- Rig compatibility --[[ Remember, the Torso is a part of the player's character, not his humanoid This means we need to get it from the character aka the humanoid's parent. --]] explosion.Parent = game.Workspace explosion.Shape = "Ball" explosion.BrickColor = BrickColor.new("New Yeller") explosion.Material = "Neon" explosion.Size = Vector3.new(15, 15,15) explosion.CanCollide = false explosion.Position = Torso.Position explosion.Anchored = true for i = 0, 1, 0.02 do wait(0.01) explosion.Transparency = i end hum:TakeDamage(5) game.Debris:AddItem(explosion, 1e-8) -- much neater way of writing it elseif hit.Anchored and hit.CanCollide == true then for i = 1,10 do local part = kiblast:Clone() part.Size = Vector3.new(0.5 , .5, .5) part.CFrame = kiblast.CFrame part.Parent = workspace part.BodyVelocity.Velocity = Vector3.new(math.random(-15,15), math.random(-15,15), math.random(-15,15)) * 5 --[[ without the times 50 it goes at a random speed i think --]] game.Debris:AddItem(part, 1) end end end)
If this answers your question, please be sure to accept my answer so the helpers know this article is closed.
Kind regards, Rod455
add a debounce