ServerScriptService.BulletCreate:18: attempt to index nil with 'PlayerGui' ^ That's the error.
I'm trying to make a gun when it hits someones head, it shows a text saying 'HEADSHOT!'
This is my code, a normal script.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Shot")
local ShotBullet = false
remoteEvent.OnServerEvent:Connect(function(player, gunPos, mosPos)
local Bullet = Instance.new("Part")
Bullet.Name = "Bullet"
Bullet.Parent = game.Workspace
Bullet.BrickColor = BrickColor.new("Really black")
Bullet.Size = Vector3.new(0.28, 0.29, 0.25)
Bullet.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5
Bullet:Destroy()
if hit.Parent:FindFirstChild("Head") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10
game.Players.LocalPlayer.PlayerGui.ScreenGui.Headshot.Visible = true
wait(2)
game.Players.LocalPlayer.PlayerGui.ScreenGui.Headshot.Visible = false
end
end
end)
local bulletspeed = 300
Bullet.CFrame = CFrame.new(gunPos, mosPos)
Bullet.Velocity = Bullet.CFrame.lookVector * bulletspeed
wait(1)
Bullet:Destroy()
end)

1 comment
Alright, thank you. I will try using another remote event.