Hey !
I’m trying to a infinite staircase. I’m trying to clone the model when the player touches the detection area, and reposition it at the bottom of the staircase, then destroy the detection part so it won’t create it again and again. The script “works” but the model isn’t cloned correctly and repositionned :
local summonedStairCase = game.ReplicatedStorage.StairSummoned
script.Parent.DetectionArea2.Touched:Connect(function()
local s = script.Parent:Clone()
script.Parent:WaitForChild("DetectionArea2").CFrame = script.Parent.DetectionArea2.CFrame + Vector3.new(0,11.161,0)
script.Parent.DetectionArea2:Destroy()
summonedStairCase.Value += 1
print("Summoning a new staircase")
end)
summonedStairCase.Changed:Connect(function()
-- Do stuff here
end)
it its model it should be welded if you want to reposition and it needs a primary part and you have to change the CFrame of the primary part
OOf I have more than 300 pieces inside
First thing you should do is add a Debounce
because the Touched event will fire every time any body part touches the part which can be many times a second.
A debounce looks like:
local debounce = false
script.Parent.Touched:Connect(function()
if not debounce then -- if debounce is false
debounce = true
-- do rest of stuff
else
-- already touched part
end
end)
Then to move the whole model you firstly need to make sure the Model has a PrimaryPart then you can use the function SetPrimaryPartCFrame
on the Model.
Good morning/afternoon.
You can attempt to use something like s:MoveTo(position here)
then define a position.
By using :MoveTo()
, you’re telling a model to move to a Vector3 in the workspace.
Hope this helped, good luck.
-Expistic