how do i make this script be aimable

Tamakire

New Member
Apr 29, 2019
21
0
1
Roblox
Tamakire
debounce = {}
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player)
if debounce[player] then return end
debounce[player] = true
local AlreadyTouched = false
local char = player.Character
local Fireball = game.ServerStorage.Fireball:Clone()
local forward = char.UpperTorso.CFrame.lookVector
Fireball.Position = char.UpperTorso.Position + forward * 2.0
Fireball.CFrame = char.UpperTorso.CFrame + forward * 2.0
Fireball.Parent = workspace
Fireball.CanCollide = true
Fireball:SetNetworkOwner(nil)
local BV = Instance.new("BodyVelocity")
BV.Parent = Fireball
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BV.Velocity = forward * 100

Fireball.Touched:Connect(function(Hit)
if Hit and Hit.Parent and not AlreadyTouched then
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid and Humanoid.Parent ~= char then
AlreadyTouched = true
Humanoid:TakeDamage(25)
Fireball: Destroy()
end
end
end)

wait(2)

if not AlreadyTouched then
local boom = Instance.new("Explosion", workspace)
boom.Position = Fireball.Position
boom.BlastRadius = 0
boom.BlastPressure = 0
Fireball: Destroy()
end
debounce[player] = nil
end)

how do i make this script be aimable with mouse
 

CallMeKY

Moderator
Ultra
Feb 25, 2018
716
128
43
Maine, USA
Roblox
CallMeKY
Discord
CallMeKY#5012
debounce = {}
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player)
if debounce[player] then return end
debounce[player] = true
local AlreadyTouched = false
local char = player.Character
local Fireball = game.ServerStorage.Fireball:Clone()
local forward = char.UpperTorso.CFrame.lookVector
Fireball.Position = char.UpperTorso.Position + forward * 2.0
Fireball.CFrame = char.UpperTorso.CFrame + forward * 2.0
Fireball.Parent = workspace
Fireball.CanCollide = true
Fireball:SetNetworkOwner(nil)
local BV = Instance.new("BodyVelocity")
BV.Parent = Fireball
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BV.Velocity = forward * 100

Fireball.Touched:Connect(function(Hit)
if Hit and Hit.Parent and not AlreadyTouched then
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid and Humanoid.Parent ~= char then
AlreadyTouched = true
Humanoid:TakeDamage(25)
Fireball: Destroy()
end
end
end)

wait(2)

if not AlreadyTouched then
local boom = Instance.new("Explosion", workspace)
boom.Position = Fireball.Position
boom.BlastRadius = 0
boom.BlastPressure = 0
Fireball: Destroy()
end
debounce[player] = nil
end)

how do i make this script be aimable with mouse
If you only want to use a mouse, the easiest way is probably to use GetMouse and the Hit property whenever Button1Down is fired.
 

WizardOfHills

Active Member
Jul 21, 2018
316
48
28
Roblox
WizardOfHills
First, the LocalScript must provide the second parameter, let's name it aim calculated as game.Players.LocalPlayer.GetMouse().Hit.Position. GetMouse has to be called in LocalScript. Local script will need to be remodelled, because as far as I can remember in the original it is triggered by GUI button, so mouse will be at the button and not at the target.

Next forward should be defined as (aim-char.UpperTorso.Position).Unit
 

Tamakire

New Member
Apr 29, 2019
21
0
1
Roblox
Tamakire
First, the LocalScript must provide the second parameter, let's name it aim calculated as game.Players.LocalPlayer.GetMouse().Hit.Position. GetMouse has to be called in LocalScript. Local script will need to be remodelled, because as far as I can remember in the original it is triggered by GUI button, so mouse will be at the button and not at the target.

Next forward should be defined as (aim-char.UpperTorso.Position).Unit
i kinda edited ur script and made it into a script that works when player presses [key]
 

WizardOfHills

Active Member
Jul 21, 2018
316
48
28
Roblox
WizardOfHills
i kinda edited ur script and made it into a script that works when player presses [key]
Then you are pretty much done.
Code:
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player, aim) 
[...]
local forward = (aim - char.UpperTorso.Position).Unit
[...]
You may want to safeguard against aiming backward. Just calculate dot product between new forward and old value (char.UpperTorso.CFrame.lookVector). If it is 0 or negative this means player shoots backward. If it is greater than 0.5 this means it is in front 120 degrees.
 

Tamakire

New Member
Apr 29, 2019
21
0
1
Roblox
Tamakire
i kinda edited ur script and made it into a script that works when player presses [key]
Then you are pretty much done.
Code:
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player, aim)
[...]
local forward = (aim - char.UpperTorso.Position).Unit
[...]
You may want to safeguard against aiming backward. Just calculate dot product between new forward and old value (char.UpperTorso.CFrame.lookVector). If it is 0 or negative this means player shoots backward. If it is greater than 0.5 this means it is in front 120 degrees.
the script that i made is a normal script in server script service its not a local script sooo do i put the code on the local script??

Local Script = inside starter character scripts

local UserInputService = game:GetService("UserInputService")
local Remote = game.ReplicatedStorage.Fire
local player = game.Players.LocalPlayer
local Char = player.Character
local Animation = Instance.new("Animation")
Animation.AnimationId = 'rbxassetid://3199343173'

UserInputService.InputBegan:Connect(function(key, IsTyping)
if IsTyping then return end
if key.KeyCode == Enum.KeyCode.Z then
Remote:FireServer()
local LoadAnimation = Char.Humanoid:LoadAnimation(Animation)
LoadAnimation:Play()
end
end)

Normal Script = in server script service


debounce = {}

game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player, aim)
if debounce[player] then return end
debounce[player] = true
local AlreadyTouched = false
local char = player.Character
local Fireball = game.ServerStorage.Fireball:Clone()
local aim = game.Players.LocalPlayer:GetMouse().HitPosition
local forward = (aim - char.UpperTorso.Position).Unit
Fireball.Position = char.UpperTorso.Position + forward * 2.0
Fireball.CFrame = char.UpperTorso.CFrame + forward * 2.0
Fireball.Parent = workspace
Fireball.CanCollide = true
Fireball:SetNetworkOwner(nil)
local BV = Instance.new("BodyVelocity")
BV.Parent = Fireball
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BV.Velocity = forward * 100
Fireball.Touched:Connect(function(Hit)
if Hit and Hit.Parent and not AlreadyTouched then
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid and Humanoid.Parent ~= char then
AlreadyTouched = true
Humanoid:TakeDamage(25)
Fireball: Destroy()
end
end
end)

wait(2)
if not AlreadyTouched then
local boom = Instance.new("Explosion", workspace)
boom.Position = Fireball.Position
boom.BlastRadius = 0
boom.BlastPressure = 0
Fireball: Destroy()
end
debounce[player] = nil
end)
 

WizardOfHills

Active Member
Jul 21, 2018
316
48
28
Roblox
WizardOfHills
Look at line Remote:FireServer() . This is where you must supply the aim parameter. You have already local player as player. So the only part you need to change is Remote:FireServer(player:GetMouse().Hit.Position)
 

Tamakire

New Member
Apr 29, 2019
21
0
1
Roblox
Tamakire
Look at line Remote:FireServer() . This is where you must supply the aim parameter. You have already local player as player. So the only part you need to change is Remote:FireServer(player:GetMouse().Hit.Position)
i did make it work but when im moving and cast the spell, the spell only looks at one way
 
General
Help Users
    SavageFanBoy SavageFanBoy: where are you