This script is a localscript/serverscript duo that, when a player clicks a particular area, will spawn a ray from the vehicle seat of the helicopter and act as a gun. The script doesn’t work, and I have to be honest, I have no idea why or how to make it work. Could someone help me?
---- serversided code
local mouse = Player:GetMouse()
local firing = script.Parent.VehicleSeat.firing --- code is inside helicopter
mouse.Button1Down:Connect(function()
firing:FireServer(true,mouse)
end)
mouse.Button1Up:Connect(function()
firing:FireServer(false,mouse)
end)
---server sided code, located in a script inside remote event
local firin = false
script.Parent.OnServerEvent:Connect(function(value,mouse)
firin = true
wait()
while firin do
wait()
if mouse.Target.Parent ~= script.Parent.Parent.Parent and mouse.Target.Parent.Parent ~= script.Parent.Parent.Parent then
for i = 1, math.random(4,5) do
--script.Parent.Parent.firing:Play()
local theTar = mouse.Hit + Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5))
local bull = Instance.new("Part")
bull.Parent = game.Workspace
bull.CFrame = CFrame.new((theTar + script.Parent.Parent.Position)/2,script.Parent.Parent.Position) --- script.Parent.Parent is the vehicle seat
bull.CanCollide = false
bull.BrickColor = BrickColor.new(24)
bull.Anchored = true
bull.Size = Vector3.new(1,1.2,1)
game.Debris:AddItem(bull,0.1)
local mesher = Instance.new("BlockMesh")
mesher.Parent = bull
mesher.Scale = Vector3.new(0.2, 0.2, (mouse.Hit - script.Parent.Parent.Position).magnitude)
script.Cle:clone().Parent = bull
local ex = Instance.new("Explosion")
ex.BlastRadius = 5
ex.BlastPressure = 5000
ex.Position = theTar
ex.Parent = game.Workspace
wait(0.06)
end
end
end
end)
Output always just says that I can’t use mouse in the serverside code since it’s a boolean; I’ve tried directly sending mouse.Target and mouse.Hit to it, but the issue just persisted since I couldn’t get the parent of mouse.Target.Parent.