the main part of it is working, it is just the placing part that i need help with (nothing places, and i get an error). I have two errors, and two scripts. here are the scripts:
Local script: Most of this works
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Structure = ReplicatedStorage:WaitForChild("PlaceStructure")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local StructureFrame = script.Parent.StructureFrame
local char = player.Character or player.Character:Wait()
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
local yBuildingOffset = 5
local maxPlacingDistance = 50
local rKeyIsPressed = false
local PlacingStructure = false
local placedStructure
local Structures = ReplicatedStorage:WaitForChild("Structures")
--Loop through GUI's
for _, StructureButton in pairs(StructureFrame:GetChildren()) do
if StructureButton:IsA("TextButton")then
StructureButton.MouseButton1Up:connect(function()
StructureFrame.Visible = false
local yOrientation = 0
local GoodToPlace = false
local placeStructure
if PlacingStructure == false then
PlacingStructure = true
local clientStructure = Structures:FindFirstChild(StructureButton.Name):Clone()
clientStructure.BrickColor = BrickColor.new("Forest green")
clientStructure.Material = "Neon"
clientStructure.Parent = workspace
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)
if hit and (hit:IsA("Terrain") or hit.Name:lower() == "terrain") and (HumanoidRootPart.Position - clientStructure.Position).Magnitude < maxPlacingDistance then
GoodToPlace = true
clientStructure.BrickColor = BrickColor.new("Forest green")
else
GoodToPlace = false
clientStructure.BrickColor = BrickColor.new("Crimson")
end
local newAnglesCFrame = CFrame.Angles(0,math.rad(yOrientation), 0)
local newCFrame = CFrame.new(position.X,position.Y + yBuildingOffset,position.Z)
clientStructure.CFrame = newCFrame * newAnglesCFrame
end)
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
rKeyIsPressed = true
local rotationSpeed = 5
while rKeyIsPressed do
wait()
if PlacingStructure == true then
yOrientation = yOrientation + rotationSpeed
end
end
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
rKeyIsPressed = false
end
end)
UIS.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if PlacingStructure == true then
if GoodToPlace == true then
local structureCFrame = clientStructure.CFrame
placedStructure = placeStructure:InvokeServer(clientStructure.Name,structureCFrame)
if placeStructure == true then
PlacingStructure = false
clientStructure:Destroy()
StructureFrame.Visible = true
end
end
end
end
end)
end
end)
end
end
a server script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = replicatedStorage:WaitForChild("PlaceStructure")
local structures = replicatedStorage:WaitForChild("Structures")
PlaceStructure.OnServerInvoke:connect(function(player,StructureName, StructureCFrame)
local crafted
local RealStructure = structures:FindFirstChild(StructureName)
if RealStructure then
RealStructure.CFrame = StructureCFrame
RealStructure.Parent = workspace
crafted = true
else
crafted = false
end
return crafted
end)
my errors:
OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available - Server - RemoteHandler:5
Players.Kimathi4theWin.PlayerGui.MainGui.StructureHandler:89: attempt to index nil with 'InvokeServer' - Client - StructureHandler:89
thank you.