I want to make a script that spawn a house a a specific plot when you click a button. The problem is that only one of the buttons work. I have everything in the right spot, named everything accordingly, and there are no errors in the output.
Local Script:
local C = script.Parent:GetChildren()
local Houses = game.Workspace:WaitForChild("Houses")
local PlotNum = script.Parent.PlotNum
local Event = game.ReplicatedStorage.HouseSelectEvent
local E = true
local Player = game.Players.LocalPlayer
for i = 1,#C do
if C[i]:IsA("ImageButton") then
C[i].MouseButton1Click:Connect(function()
if E == true then
E = false
local Home = Houses:FindFirstChild(C[i].Name).Name
Event:FireServer(Home, PlotNum.Value)
print(Player, Home, PlotNum.Value)
wait(5)
E = true
else return
end
end)
end
end
Script:
local Event = game.ReplicatedStorage.HouseSelectEvent
local Houses = game.Workspace.Houses
local C = Houses:GetChildren()
local Players = game:GetService("Players")
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
function SpawnHouse(Player, House, Plot)
for i = 1,#C do
if C[i].Name == House then
print(Player, House, Plot)
local clone = C[i]:Clone()
clone.Parent = Plot
clone:MakeJoints()
clone.Door.SurfaceGui.Owner.Text = Player.Name
clone:SetPrimaryPartCFrame(Plot.CFrame)
local ID = Player.UserId
local userId = tonumber(ID)
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
Plot:FindFirstChildWhichIsA("Model").WindowBody.Window.SurfaceGui.ImageLabel.Image = content
else return
end
end
end
Event.OnServerEvent:Connect(function(Player, House, PlotNum)
local OwnsHouse = Player:FindFirstChild("OwnsHouse")
Plot = game.Workspace:FindFirstChild("Plot "..PlotNum)
Owner = Plot.Owner
if ((Owner.Value == Player.Name or Owner.Value == "") and OwnsHouse.Value == false) and OwnsHouse.Value == false or (Owner.Value == Player.Name and OwnsHouse.Value == true) then
Owner.Value = Player.Name
OwnsHouse.Value = true
if Plot:FindFirstChildWhichIsA("Model") then
Plot:FindFirstChildWhichIsA("Model"):Destroy()
end
SpawnHouse(Player, House, Plot)
else
return
end
Players.PlayerRemoving:Connect(function(Plr)
if Plr.Name == Owner.Value and Plot then
Plot:FindFirstChildWhichIsA("Model"):Destroy()
Owner.Value = ""
end
end)
end)
This is what the output prints when I click the different buttons:
You can see when I click the button for the modern house, it prints just fine and spawns in the house. When I click the button for the Daycare, it only prints in the client script, and doesn’t spawn in the Daycare.