Attempt to index Boolean with 'InvokeServer'

local replicatedstorage = game.ReplicatedStorage
local placer = game.ReplicatedStorage:WaitForChild("placer")
local structures = game.ReplicatedStorage:WaitForChild("Structures")
local userinputservice = game:GetService("UserInputService")

local runservice = game:GetService("RunService")
local player = game.Players.LocalPlayer
local structureFrame = script.Parent.Frame
local char = player.Character or player.Character:Wait()
local humanoidrootpart = char:WaitForChild("HumanoidRootPart")

local mouse = player:GetMouse()

local goodtoplace = false
local yBuildingOffset = 5
local rKeyispressed = false
local placingstructure = false

for i, v in pairs(structureFrame:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Up:Connect(function()
			structureFrame.Visible = false

			local yOrientation = 0
			local placer
			print("check") -- works
			if placingstructure == false then
				placingstructure = true
				
				local clientstructure = structures:FindFirstChild(v.Name):Clone()
				clientstructure.CanCollide = false
				clientstructure.Parent = workspace
                print("check") --No print
				local StartingCframe = CFrame.new(0, -2, -15)
				clientstructure.CFrame = humanoidrootpart.CFrame:ToWorldSpace(StartingCframe)

				runservice.RenderStepped:Connect(function()
					local mouseray = mouse.UnitRay
					local castray = Ray.new(mouseray.Origin, mouseray.Direction * 1000)
					local ignorelist = {clientstructure, char}
					local hit, position = workspace:FindPartOnRayWithIgnoreList(castray, ignorelist)
                    print("check") -- no print
					if hit and hit.Shape == Enum.PartType.Block then
						print("check") -- no print
						goodtoplace = true
					else
						goodtoplace = false
					end


					local NewAngleCframe = CFrame.Angles(0, math.rad(yOrientation), 0)
					local NewCframe = CFrame.new(position.X, position.Y + yBuildingOffset, position.Z)
					clientstructure.CFrame = NewCframe * NewAngleCframe
				end)
				userinputservice.InputBegan:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.R  then
						rKeyispressed = true

						local rotationspeed = 5
						while rKeyispressed do
							task.wait()
							if placingstructure == true then
								yOrientation = yOrientation	+ rotationspeed
							end
						end
					end
				end)
				userinputservice.InputEnded:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.R  then
						rKeyispressed = false
					end
				end)
				userinputservice.InputBegan:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseButton1 then
						if placingstructure == true  then
							if goodtoplace == true then
								local StructureCframe = clientstructure.CFrame
								placer = placingstructure:InvokeServer(clientstructure.Name, StructureCframe)

								if placer == true then
									placingstructure = false 
									clientstructure:Destroy()
									structureFrame.Visible = true
								end
							end
						end
					end
				end)
			end
		end)
	end
end

This is a placement system I inspired from the devking for my game.
I think it has something to do with the age of this code but I got multiple errors from copying it. I debugged most of it, but I struggled with this one about indexing a boolean with invokeserver and I can’t understand what that means.

1 Like

Which exact line in the script errors?

In this code block you are using method :InvokeServer() on a boolean. The errors means that.

Attempt to index X with Y usually means that X doesn’t have something that has the name Y. Just like how attempt to index boolean with InvokeServer here is. It means that you are using that method on a boolean which doesn’t support that method.

1 Like

You are doing placingstructure:InvokeServer() which is causing the issue. You must invoke your RemoteFunction, just like @K4ttt_i (just beat me to it lol)

This is deprecated. You should convert to workspace:Raycast() instead.

1 Like

Why is this code also quite terrible? You are using variables with same names which is simply the worst way to code.

Also the fix could be:

Replacing:

placer = placingstructure:InvokeServer(clientstructure.Name, StructureCframe)

With:

placer = structures:InvokeServer(clientstructure.Name, StructureCframe)

Yay I won! Where is my gold medal now?

(I love it how helping people becomes a sport sometime. Really makes it 1000x fun.)

1 Like

Why is this code also quite terrible? You are using variables with same names which is simply the worst way to code.

I just copied it from the dev king. how would you code it any differently may I ask.? I’m a beginner.

Also thank you for taking time to help me.

That’s a bit tough to say as I am on mobile
But basically, see if there are any overwritten variables like the “placer” variable which you are over-riding.

1 Like

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