So I have a gun with a handle and a part welded to it called firepoint, where I want the bullet to fire out of. Inside the tool I have the fastcast module, one client script and one server script, as well as a remote event called fire and one called shoot, shoot deals damage and fire fires a bullet. here is the server side script
local debounce = 0
local FastCast = require(script.Parent.FastCastRedux)
local caster = FastCast.new()
local FirePoint = script.Parent.Part
FastCast.VisualizeCasts = false
local bulletFolder = game.Workspace.BulletFolder
local function fire(player, mousePosition)
local origin = FirePoint.OriginPosition
local direction = (mousePosition - origin).Unit
caster:Fire(origin, direction, 20)
end
local bulletTemplate = Instance.new("Part")
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
bulletTemplate.Size = Vector3.new(1.5,1.5,1.5)
bulletTemplate.Shape = "Ball"
bulletTemplate.BrickColor = BrickColor.new("Yellow flip/flop")
local castPerams = RaycastParams.new()
castPerams.IgnoreWater = true
castPerams.FilterType = Enum.RaycastFilterType.Blacklist
local castBehavior = FastCast.newBehavior()
castBehavior.Acceleration = 10
castBehavior.RaycastParams = castPerams
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate
local function onLengthChanged(cast,lastPoint,direction,length,velocity,bullet)
if bullet then
local bulletLength = bullet.Size.Z/2
local offset = CFrame.new(0,0,-(length - bulletLength))
bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end
local function Shoot(player,Target)
if debounce == 0 then
debounce = 1
if Target ~= nil then
local human = Target.Parent:findFirstChild("Humanoid")
if human then
if Target.Name == "Head" then
human:TakeDamage(30)
elseif Target.Name == "HumanoidRootPart" then
human:TakeDamage(30)
else
human:TakeDamage(30)
end
end
end
script.Parent.Handle.Fire:Play()
debounce = 0
end
end
script.Parent.Equipped:Connect(function()
castPerams.FilterDescendantsInstances = {script.Parent.Parent, bulletFolder}
end)
script.Parent.Fire.OnServerEvent:Connect(fire)
script.Parent.Shoot.OnServerEvent:Connect(Shoot)
caster.LengthChanged:Connect(onLengthChanged)
and then I want to call it when the tool is activated, this is the client sided script
local var = 10
local shouldFollowMouse = false
local animid = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("Animate").toolnone.ToolNoneAnim.AnimationId
local doNotInterrupt = false
local Players = game:GetService("Players")
local anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.ReloadAnim)
local function thingy()
local character = game.Players.LocalPlayer.Character
if character.Parent == "Backpack" then return end
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local function click()
if var > 0 then
script.Parent.Fire:FireServer(mouse.Hit.Position)
var = var - 1
script.Parent.Shoot:FireServer(mouse.Target)
local gun = script.Parent.Handle
else
if doNotInterrupt == false then
doNotInterrupt = true
script.Parent.Handle.Reload:Play()
anim:Play()
wait(1)
var = 10
doNotInterrupt = false
end
end
end
script.Parent.Activated:Connect(click)
end
script.Parent.Equipped:Connect(thingy)
now it does damage and all, but dosn’t shoot a bullet?
please help.