Hello, I need to make the laser gun fire the laser beam but when I enter the game and click it does absolutely nothing, what is wrong with my code? does someone knows?
localscript:
local LaserGun = script.Parent
LaserGun.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
local RemoteEvent = game.ReplicatedStorage:FindFirstChild("LaserEvent")
RemoteEvent:FireServer(Mouse)
end)
end)
serverscript:
local Debris = game:GetService("Debris")
local LaserGun = script.Parent
local Tip = LaserGun:WaitForChild("Tip")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Event = game.ReplicatedStorage:FindFirstChild("LaserEvent")
Event.OnServerEvent:Connect(function(player, Mouse)
local Laser = Ray.new(Tip.CFrame.p, (Mouse.Hit.p - Tip.CFrame.p).unit * 300)
local HitPart, HitPosition = game.Workspace:FindPartOnRay(Laser, Character, false, true)
local LaserBeam = Instance.new("Part", game.Workspace)
LaserBeam.BrickColor = BrickColor.new("New Yeller")
LaserBeam.FormFactor = "Custom"
LaserBeam.Material = "Neon"
LaserBeam.Transparency = 0.25
LaserBeam.Anchored = true
LaserBeam.CanCollide = false
local LaserDistance = (Tip.CFrame.p - HitPosition).Magnitude
LaserBeam.Size = Vector3.new(0.3, 0.3, LaserDistance)
LaserBeam.CFrame = CFrame.new(Tip.CFrame.p, HitPosition) * CFrame.new(0, 0, -LaserDistance/2)
Debris:AddItem(LaserBeam, 0.1)
if HitPart then
local HitHumanoid = HitPart.Parent:FindFirstChild("Humanoid")
if not HitHumanoid then
HitHumanoid = HitPart.Parent.Parent:FindFirstChild("Humanoid")
end
if HitHumanoid then
end
local Humanoid = HitHumanoid
local h = Humanoid
h.WalkSpeed = 0
print("Velocidad bajada")
wait(5)
h.WalkSpeed = 17
end
end)