Answered step by step
Verified Expert Solution
Question
1 Approved Answer
- - Replace with the name of your projectile model or part local projectileName = Blast - Wizard local tool = script.Parent.Parent - - Go
Replace with the name of your projectile model or part
local projectileName "BlastWizard"
local tool script.Parent.Parent Go up two levels to reach the Handle of the StaffWizard tool
Configurable parameters
local damageAmount Adjust the damage as needed
Preload the projectile model from ReplicatedStorage
local replicatedStorage game:GetServiceReplicatedStorage
local projectile replicatedStorage:WaitForChildprojectileName
local function shootProjectile
local player game.Players.LocalPlayer
local mouse player:GetMouse
local character player.Character or player.CharacterAdded:Wait
local humanoid character:WaitForChildHumanoid
local origin humanoid.Parent:WaitForChildHumanoidRootPartPosition
local direction mouseHit.p originunit
local newProjectile projectile:Clone
newProjectile.Parent game.Workspace
newProjectile.Position origin
Attach BodyPosition to update the position of the projectile
local bodyPosition Instance.newBodyPosition
bodyPosition.Position origin direction Adjust the distance as needed
bodyPosition.MaxForce Vectornewmathhuge, math.huge, math.huge
bodyPosition.Parent newProjectile
local hasDealtDamage false Flag to ensure damage is applied only once
local function onTouchedhit
if hasDealtDamage then
return
end
local hitHumanoid hit.Parent:FindFirstChildOfClassHumanoid
if hitHumanoid and hit.Parent ~ humanoid.Parent then
Deal damage or perform other actions as needed
hitHumanoid:TakeDamagedamageAmount
hasDealtDamage true Set the flag to true to prevent further damage
newProjectile:Destroy
elseif hit.Parent:IsATerrain then
Handle terrain collision if needed
newProjectile:Destroy
end
end
newProjectile.Touched:ConnectonTouched
Remove the projectile after seconds adjust as needed
wait
newProjectile:Destroy
end
tool.Activated:ConnectshootProjectile
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started