Hey everyone!
I was working a building system for my new game Conquest!
Here are the issues:
- It can’t find the built/structure it is trying to make
Output: unable to cast value to std::string
The issue can be found in:
local BuiltFolder = Builts:FindFirstChild(Type) --- Error
local TeamFolder = BuiltFolder:FindFirstChild(Team) --- Error
local ClientBuilt = TeamFolder:FindFirstChild(structurebutton.Name):Clone() --- Error
- It can’t place the built/structure and the client structure only shows red even though it was within the max distance
The issue can be found in:
if hit and (HumanoidRootPart.Position - Base.Position).Magnitude < MaxDistance then
GoodPlacement = true
Built.BrickColor = BrickColor.new("Forest green")
else
GoodPlacement = false
Built.BrickColor = BrickColor.new("Really red")
end
- When I click on the cancel built button it shows some noticeable amount of lag when it’s clicked on too much
The issue can be found in:
BreakButton.MouseButton1Click:Connect(function() --- This causes a memory leak and lag issues
PlacingBuilt = false
ClientBuilt:Destroy()
BreakButton.Visible = false
TopHeader.Visible = true
end)
What had I tried so far:
I had tried to find/search some topics in devforum that had solve the “unable to cast value to std::string” error. Well, I did but not one of them give me enough information/clues to figure out the problem/error. Most of the topics I found was about Http request errors and that was not what I’m looking for.
Explorer:
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Builts = ReplicatedStorage:WaitForChild("Models")
local PlaceBuilt = ReplicatedStorage:WaitForChild(" y189d !T@L!d1 y;8dlool1; ld1 12l19 . ,. , .e.3;232..!Le3imjnDIlIi. ,2,ki#LKio32loJllil")
local UIS = game:GetService("UserInputService")
local RunS = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local StructureFrame = script.Parent
local char = Player.Character or Player.Character:Wait()
local Team = Player.TeamColor
local mouse = Player:GetMouse()
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
local BreakButton = StructureFrame.Parent.Parent.Parent.CancelButton
local TopHeader = StructureFrame.Parent.Parent.Parent.Frame
local YBuildingOffset = 0
local MaxDistance = 40
local RKeyPressed = false
local PlacingBuilt = false
for _, structurebutton in pairs(StructureFrame:GetChildren()) do
if structurebutton:IsA("ImageButton") then
local Type = structurebutton.Type.Value
structurebutton.MouseButton1Up:Connect(function()
BreakButton.Visible = true
TopHeader.Visible = false
StructureFrame.Parent.Parent.Visible = false
local YRotation = 0
local GoodPlacement = false
local placedStructure
if PlacingBuilt == false and Builts:FindFirstChild(Type) then
PlacingBuilt = true
local BuiltFolder = Builts:FindFirstChild(Type) --- Error
local TeamFolder = BuiltFolder:FindFirstChild(Team) --- Error
local ClientBuilt = TeamFolder:FindFirstChild(structurebutton.Name):Clone() --- Error
for i,Built in pairs(ClientBuilt:GetDescendants()) do
if Built:IsA("Part") then
Built.BrickColor = BrickColor.new("Forest green")
Built.Material = "Neon"
Built.Transparency = 0.4
Built.CanCollide = false
ClientBuilt.Parent = workspace
local Base = ClientBuilt.PrimaryPart
--print(Built)
local StartingPosition = CFrame.new(0, -2, -15)
Base.CFrame = HumanoidRootPart.CFrame:ToWorldSpace(StartingPosition)
RunS.RenderStepped:Connect(function()
local MousePos = mouse.UnitRay
local CastRay = Ray.new(MousePos.Origin, MousePos.Direction*1000)
local ignorelist = {ClientBuilt, char}
local hit, position = workspace:FindPartOnRayWithIgnoreList(CastRay, ignorelist)
if hit and (HumanoidRootPart.Position - Base.Position).Magnitude < MaxDistance then
GoodPlacement = true
Built.BrickColor = BrickColor.new("Forest green")
else
GoodPlacement = false
Built.BrickColor = BrickColor.new("Really red")
end
local newRotationPos = CFrame.Angles(0, math.rad(YRotation), 0)
local NewCFrame = CFrame.new(position.x, position.y + YBuildingOffset, position.z)
Base.CFrame = NewCFrame*newRotationPos
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
RKeyPressed = true
local rotationSpeed = 5
while RKeyPressed do
wait()
if PlacingBuilt == true then
YRotation = YRotation + rotationSpeed
end
end
elseif input.UserInputType == Enum.UserInputType.MouseButton1 and PlacingBuilt == true and GoodPlacement == true then
local StructureCFrame = Base.CFrame
placedStructure = PlaceBuilt:InvokeServer(ClientBuilt.Name, StructureCFrame)
if placedStructure == true then
PlacingBuilt = false
StructureFrame:Destroy()
ClientBuilt:Destroy()
TopHeader.Visible = true
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
RKeyPressed = false
end
end)
end
end
BreakButton.MouseButton1Click:Connect(function() --- This causes a memory leak and lag issues
PlacingBuilt = false
ClientBuilt:Destroy()
BreakButton.Visible = false
TopHeader.Visible = true
end)
end
end)
end
end
The game Conquest! won’t be finished without this building system which is a major part of the game.
Any help is appreciated!
Solved Issues: 1 and 3