Yo, i'm back after 6 months and I came across a problem with my gun script, every time I shoot at the enemy it doesn't work, here's the part of the code that i think has that problem.
Server Script UPDATED
local event = game.ReplicatedStorage.ShootGun local damage = math.random(20,60) local range = 50 local gunshot = script.Parent.gunshot function createBeam(pos) print(8) local part = Instance.new("Part", workspace) part.Position = pos print(9) local at1 = Instance.new("Attachment", part) local at2 = Instance.new("Attachment", script.Parent.Handle) print(10) local beam = Instance.new("Beam", script.Parent.Handle) beam.Texture = "http://www.roblox.com/asset/?id=1274378728" print(11) end event.OnServerEvent:Connect(function(player, mousePos, originPos) print(1) local direction = (mousePos - originPos).Unit * range print(2) local result = workspace:Raycast(originPos, mousePos) if result then print(3) print(4) local character = result.Instance.Parent local humanoid = character:FindFirstChild("Humanoid") print(5) if humanoid then print(6) humanoid:TakeDamage(damage) end print(7) createBeam(result.Instance.Position) gunshot:Play() end end)
Local Script
local tool = script.Parent local origin = tool:WaitForChild("Handle").Position local player = game.Players.LocalPlayer local mouse = player:GetMouse() local event = game.ReplicatedStorage.ShootGun local recoil = false local recoilTime = 0.4 tool.Activated:Connect(function() if recoil then return end recoil = true local mousePosition = mouse.Target.Position event:FireServer(mousePosition, origin) wait(recoil) recoil = false end)
And What's the Error