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
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
There is a really good placement system tutorial, I can link it, but it’s more similar to Restaurant Tycoon 2 than Bloxburg
(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.)
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