Cloning gone wrong

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make when the button clicked, a model(house) will clone if the model’s(house)
    name is equal to the button name

  2. What is the issue? Include screenshots / videos if possible!

    model(house)cloned more than 1 also one of them is not equal to the button name that
    been clicked
    this is the screenshot:

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

    I can't find any solutions  so far
    

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
I Used remote event server-side

this is code from server script

local houses = game.ReplicatedStorage.House:GetChildren()
local pos = game.Workspace.PromptInterract.HouseOwning:GetChildren()
local event = game.ReplicatedStorage.Remotes.CloneHouseOne1

event.OnServerEvent:Connect(function(player)
	print("getting player from frame")
	local frame = player.PlayerGui:WaitForChild("HouseGui"):WaitForChild("HouseFrame").ScrollingFrame:GetChildren()
	print("getting frame children")
	for i , v in pairs(frame)do
		for k , p in pairs(pos)do
			print("looping childrens")
			for _ , house in pairs(houses)do
				if v.Name == house.Name and v:WaitForChild("Name").Value == house.Name then
					print(house.Name , p:WaitForChild("PlayerPlcae").Value == player.Name , v.Name == house.Name)
					print("same")
					if p:WaitForChild("PlayerPlcae").Value == player.Name then
						print("same")
						local clone = house:Clone()
						print("cloning house")
						clone.Parent = workspace:WaitForChild(player.Name.."Stuff")
						print("set parent model")
						clone:SetPrimaryPartCFrame(p:WaitForChild("HouseSpawnPart").CFrame , CFrame.Angles(math.rad(90),0,0))
						print("select position model")
					end
				end
			end
		end
	end
end)

This is code from client-side

script.Parent.Activated:Connect(function()
	game.ReplicatedStorage.Remotes.CloneHouseOne1:FireServer()
	print("fired form server")
end)

it will be great help if anyone could help solve this problem :smiley::smiley:

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Hello EducatedPilot04!

I would assume you haven’t accounted for if someone spams the button, so in your server side, you’d have to check to see if the model has been cloned already, if it hasn’t been cloned then you’d would be able to clone it. I’m not entirely sure how your code works because it’s quite messy. But if I was to do what you’re doing I would do it like this;

step 1, Name the house that you want to put into the plot as the button

step 2, When you press the button, fire a remote event to the server with the name of that button

game.ReplicatedStorage.Remotes.CloneHouse:FireServer(script.Parent.Name)

step 3, On the server side, you’d go through your different houses and check to see if you have a house that matches what the button says

step 4, Then you’d check to see if there’s any houses in your plot, and if not, you’d just place the house in, but if there’s a house already there, you can just delete it.

This is the code that I came up with


local Locations = game.Workspace.PromptInterract.HouseOwning

Event.OnServerEvent:Connect(function(Player,House)
if game.ReplicatedStorage.House:FindFirstChild(House) then
if game.Workspace:FindFirstChild(Player.Name .. "Stuff") then
local Plot = game.Workspace:FindFirstChild(Player.Name .. "Stuff") 
if Plot:FindFirstChild("House") then
Plot:FindFirstChild("House"):Destroy()
end

local FindPosition = nil
for i,v in pairs(Locations:GetChildren()) do
if v:FindFirstChild("PlayerPlcae") then
if v.PlayerPlcae.Value == Player.Name then
FindPosition = v.PlayerPlcae.Value
end
end
end

local NewHouse = ame.ReplicatedStorage.House:FindFirstChild(House):Clone()
NewHouse.Parent = Plot
NewHouse.Name = "House"
NewHouse:SetPrimaryPartCFrame(FindPosition:WaitForChild("HouseSpawnPart").CFrame , CFrame.Angles(math.rad(90),0,0))
end
end

Hopefully you can use this as a guide to help you fix up your code. I may have misunderstood the code, but from what i’ve read, this is what I can create from it!

Hope this helps!

3 Likes

hello @TechnologyUser,

That was a long explanation :sweat_smile::sweat_smile:
BUT… how do I do your first step if the button is actually an instance button from Value??
hope you understand

So I believe the function Activated is used on TextButtons and things, so if you made it so each button had a string value inside each button with the house name you could probably do

game.ReplicatedStorage.Remotes.CloneHouse:FireServer(script.Parent.HouseValue.Value)

or you could just name each button which house they belong to

there is an error that says attempt to call a nill value
but I don’t see any problem on this line

			NewHouse:SetPrimaryPartCFrame(FindPosition:WaitForChild("HouseSpawnPart").CFrame)

Basically, the thing that will return to be “nil” would be the FindPosition, you would have to make sure it’s found

This would be the place to look if you are receiving that error.

OMG…it worked perfectly now…thank you so much…
God Bless You man

1 Like