Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Model clone not working correctly when using changed event?

so whenever the house value changes i want it to clone that house to where the slot is aka "this" but when the changed event runs and after 1 second it still doesn't even clone the house. What do i do?

local this = script.Parent
local casas = game.Workspace.Casas


this.houseval.Changed:connect(function()
	print("changed")
	wait(1)
	if this.houseval == 1 then
		local newhouse = casas.Casa1:Clone()
newhouse.Parent = this
newhouse.CFrame = this.CFrame
	end
end)

2 answers

✓ Accepted answer

First. What Phlegethon5578 said (sorry if I spelt wrong) you need to check the value .Value

Another thing is in the title of this question you said Model so since it's a Model you can't set the CFrame of it (doesn't work that way). Instead, you could set a primary part (Probably the center of the model) and use :SetPrimaryPartCFrame and set it to a part's position.

In this case I will use 0,0,0 because you can change that to whatever you want.

  1. Make sure the model has a PrimaryPart
  1. Change script:
local this = script.Parent
local casas = game.Workspace.Casas -- this is model I assume

this.houseval.Changed:Connect(function() -- use capital C, :connect is deprecated
    print("changed")
    wait(1)
    if this.houseval.Value == 1 then -- add .Value
	print('YAY')
        local newhouse = casas.Casa1:Clone() -- make sure Casa1 has Primary Part
	newhouse.Parent = this
	newhouse:SetPrimaryPartCFrame(0,0,0) -- if this is a part then part.CFrame
	-- YOU MIGHT WANNA DESTROY THE OLD HOUSE IF IT'S ALREADY IN THE SAME POSITION OR YOU WON'T SEE A DIFFERENCE
    end
end)

Hopefully this fixed your script! Do note if it does not work or error comment and I will help you to the best of my abilities.

1 comment

0

thx, i wish i would have seen this earlier because i already fixed it. This was a way more simple to change the houses position than what i did.

Your if statement needs to get the value of houseval not houseval. It should look something like this on line 8:

if this.houseval.Value == 1 then

This discussion is preserved as it was. New answers, comments, and votes are closed.