Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

ServerScriptService.BulletCreate:18: attempt to index nil with 'PlayerGui'?

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 answer

Short answer but

You cannot get the localplayer on the server.

Your option might be to send another RemoteEvent to the client to show the headshot gui on the shooter (I assume?) which may cost performance depending on how often that event is being fired.

Short answer, but that's the issue here.

1 comment

0

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

This discussion is preserved as it was. New answers, comments, and votes are closed.