Hi. It’s me again. Currently I am trying to make a game, similar to poly bridge. I made a system, which actually works good with only 1 segment, but it fails when there are 2 segments.
This is my code with some explanation added.
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
local Player_Data = player:FindFirstChild('Player_Data')
local PickedUpTrack = Player_Data:WaitForChild('PickedupTrack')
local FinalPlacement = script.Parent.FinalPlacement
if Player_Data and PickedUpTrack then
for i, v in ipairs(game.Workspace.PlacementLocations:GetChildren()) do
warn('Getting Data for Track')
warn('Name: '..v.Name)
warn('Selection Box Color: '..tostring(v.SelectionBox.Color3))
warn('Local Selection Box Color: '..tostring(Color3.fromRGB(script.Parent.SelectionBox.Color3)))
if Color3.fromRGB(v.SelectionBox.Color3) == Color3.fromRGB(script.Parent.SelectionBox.Color3) then -- This works good, but when this gets activated from the Black Segment, the black segment goes together with the Red Placement Location, which shouldn't.
print(v.Name..' is the correct piece.')
FinalPlacement.Value = v
else
return
end
end
script.Parent.SelectionBox.Adornee = nil
script.Parent.Transparency = 1
script.Parent.CanCollide = false
PickedUpTrack.Value = true
script.Parent.ProximityPrompt.Enabled = false
local Clone = script.Parent:Clone()
Clone.Parent = PickedUpTrack:WaitForChild('Track')
end
end)
I do not know, if I should compare the values with the Color3.fromRGB
or not. Alternatively, you can help me fixing the black-red problem.
Please note that the red track segment and the black one have the same scripts inside them.