So I’ve got a problem in a script which is supposed to open a UI once a brick with a specific name is touched, yet it doesn’t open a UI.
Here is the script:
local GUI = game.ReplicatedStorage.HouseSystem.Trailer
local bool = false
for _, v in pairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and v.Name == "TrailerTouchedPart" and bool == false then
bool = true
print("works")
-- code starts here
local plr = game.Players[hit.Parent.Name]
if plr:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) and bool == false and plr.HouseData:WaitForChild("TrailerOwnedSlot").Value ~= v.Parent.Parent.Parent.Name then
bool = true
GUI:Clone().Parent = plr.PlayerGui
plr.PlayerGui.Trailer.PropertyBought.Value = v.Parent.Parent.Parent
wait(5)
bool = false
elseif plr.HouseData:WaitForChild("TrailerOwnedSlot").Value == v.Parent.Parent.Parent.Name and plr.HouseData:WaitForChild("HasClaimed").Value == false and bool == false then
bool = true
game.ReplicatedStorage.HouseSystem.ClaimProperty:Clone().Parent = plr.PlayerGui
wait(1)
plr.PlayerGui.ClaimProperty.Property.Value = v.Parent.Parent.Parent
wait(5)
bool = false
elseif plr.HouseData:WaitForChild("HouseNumber").Value == v.Parent.Parent.Parent.HouseNumber.Value then
v.CanCollide = true
wait(1)
v.CanCollide = false
end
-- ends here
wait(3)
bool = false
end
end)
end
end