I have a general idea of scripting, though I'm fairly new so I don't know much about this. I'd like to know if I can touch a brick then have it spawn a model in a specific spot, then have the player who touched the brick teleport to the newly spawned model and have the model deleted after a specific time. I don't really know where else to ask this, so I'd appreciate any help.
Can I use a button to spawn a specific model in a specific place?
1 answer
Put this code into a script
Make sure to set the PrimaryPart property of the model to a part which should be the center of the model.
Edit: Added debounce
local brick = workspace.Brick --replace with the path to your brick
local model = game:GetService("ServerStorage").Model --replace with the path to your model
local destination = Vector3.new(200,0,0) --replace with the position of where the model should spawn
local debounce = false
brick.Touched:Connect(function(hit)
if debounce then return end
debounce = true
if hit.Parent.ClassName == "Model" and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) ~= nil then
local model = model:Clone()
model.Parent = workspace
model:SetPrimaryPartCFrame(CFrame.new(destination))
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(destination)
game:GetService("Debris"):AddItem(model, 30) --will remove the model after 30 seconds
wait(2)
debounce = false
end
end)
6 comments
Thanks a ton for this, my primary issue is the brick that I have set as the button constantly spawns the model as long as I'm touching it and not certain as to where I'd add a wait function.
There, I edited my answer and added a debounce. It will prevent the button from working for 2 seconds after each touch.
I sincerely appreciate your help man, works just fine.
If you don't mind me asking or if you're still around, could I ask how I would go about making the model rotate 90 degrees when it spawns?
Depends on which axis, for example to rotate it on Y axis, do something like this: model:SetPrimaryPartCFrame(CFrame.new(destination) * CFrame.Angles(0,math.rad(90),0))
That's exactly what I was looking for, thanks again
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
yes