I got an error saying Players.cikeruw.Backpack.Tool.Script:16: attempt to index nil with 'Hit'. If you cannot use Mouse.hit with server scripts how will I fix this.
This is my local script.
local Tool = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.Button1Up:Connect(function()
if Tool.Parent.Name == Player.Character.Name then
game.ReplicatedStorage.LightningBolt:FireServer()
end
end)
This is my server script
local Part = game.ReplicatedStorage.Wedge
game.ReplicatedStorage.LightningBolt.OnServerEvent:Connect(function(Player)
local Mouse = Player:GetMouse()
local Tool = script.Parent
if Tool then
if Tool.Parent.Name == Player.Character.Name then
local partclone = Part:Clone()
partclone.CanCollide = false
partclone.CFrame = Player.Character.HumanoidRootPart.CFrame
local VectorForce = Instance.new("VectorForce")
partclone.Parent = game.Workspace
VectorForce.Force = Player.Character.HumanoidRootPart.Position + Mouse.Hit.LookVector * 100
partclone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
if hit.Parent.Name == Player.Character.Name then
wait()
hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 5 * Player.leaderstats.Level.Value
wait(5)
end
end
end)
end
end
end)

1 comment
Im still confused what code will i use to use mouse.hit