Help me with my placement system script

Help me, I want to make a placement system like bloxburg but even worse version LOL, except I always get the same error “Failed to create buttons: LocalPlayer is not available”

local partToDuplicate = game.Workspace.CONSTR

local currentPart = nil

if game.Players.LocalPlayer and game.Players.LocalPlayer:IsDescendantOf(game) then
	local textButton = Instance.new("TextButton", game.Players.LocalPlayer.PlayerGui.ScreenGui)
	textButton.Text = "Duplicate"
	textButton.Size = UDim2.new(0, 100, 0, 50)
	textButton.Position = UDim2.new(0, 0, 0, 0)

	textButton.MouseButton1Click:Connect(function()
		currentPart = partToDuplicate:Clone()
		currentPart.Parent = game.Workspace
		currentPart.CanCollide = false
	end)

	
	game:GetService("RunService").RenderStepped:Connect(function()
		if currentPart ~= nil then
			local mouse = game.Players.LocalPlayer:GetMouse()
			local hit, pos, normal = game.Workspace:FindPartOnRayWithIgnoreList(
				Ray.new(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 100),
				{ currentPart }
			)
			currentPart.CFrame = CFrame.new(pos)
		end
	end)

	
	local deleteButton = Instance.new("TextButton", game.Players.LocalPlayer.PlayerGui.ScreenGui)
	deleteButton.Text = "Delete"
	deleteButton.Size = UDim2.new(0, 100, 0, 50)
	deleteButton.Position = UDim2.new(0, 110, 0, 0)

	deleteButton.MouseButton1Click:Connect(function()
		if currentPart ~= nil then
			currentPart:Destroy()
			currentPart = nil
		end
	end)
else
	warn("Failed to create buttons: LocalPlayer is not available")
end
1 Like

Exactly on which line, this error is happening though ?

I think this isn’t correct.

  1. You can’t access local player from server scripts, only local. If you have local, recommend setting a directory using script.Parent.Parent… and so on until you reach starterGUI

  2. There is a really good placement system tutorial, I can link it, but it’s more similar to Restaurant Tycoon 2 than Bloxburg

He’s using RenderStepped, which can only be run on the client (LocalScript).

I’ll take a look thanks for the help.

it’s line 9 in particular that’s messing up

local textButton = Instance.new(“TextButton”, game.Players.LocalPlayer.PlayerGui.ScreenGui)

in that case, instead of using

game:GetService("Players").LocalPlayer.PlayerGui.ScreenGui

do

local screenGui = script.Parent.ScreenGui

(this is assuming that the script thats running this is located under game.StarterGui)

also, the problem appears to be that either it cant access LocalPlayer, or it is for some unknown reason not a descendant of game (see below)

if game.Players.LocalPlayer and game.Players.LocalPlayer:IsDescendantOf(game) then
	--code i removed, its irrelevant
else
	warn("Failed to create buttons: LocalPlayer is not available")
end

as for OP, here is a youtube series about a building tycoon (if you need it, most likely you wont):

and here is the developer forum post about just the building system (no deleting, saving, etc.)

hope i helped!

Thank you so much for taking the time to help me.

1 Like

The script should be located inside ScreenGUI. StarterGUI is just something which adds ScreenGUI inside player.

It works just like

game.Players.PlayerAdded:Connect(function(player)
local screenUI = whatever --suggested inside ServerStorage
screenUI.Parent = player.PlayerGui
end)
1 Like

This is a little off topic, but try to start using worldroot:Raycast() instead of rays, they’re newer and faster than rays, which are old and probably deprecated

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.