Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

0
Alright, thank you. I will try using another remote event. xbendaiialt 44 — 3y
Ad

Answer this question