How do I make a model spawn in front of me when I press a button?

Hello, I am currently trying to make a button that when pressed spawns a model in front of me. I could really use some help.

1 Like

put said model in rep storage and make a function when u click it to set the position to your location and set the parent to workspace.

How would I set it to my location?

1 Like
[local script]
player = game.Players.localplayer
pos = player.Position

local model = game.replicatedstorage.[MODEL NAME]
model.Position = pos
model.Parent = workspace
1 Like

is this what you mean?

script.Parent.MouseButton1Click:Connect(function()

player = game.Players.localplayer
pos = player.Position

local model = game.replicatedstorage.Yrden
model.Position = pos
model.Parent = workspace

end)

yes in a local script, then that will do it but only locally if u want to do it server sided you will have to use a remote event.

1 Like

Its not working and showing an error

1 Like

put local at the start of player and pos my fault i am on mobile rn

1 Like

Alright, so insert a local script into the text button and insert this script:

script.Parent.MouseButton1Click:Connect(function()
	local HRP = game.Players.LocalPlayer.Character.HumanoidRootPart
	local model = game.ReplicatedStorage.Model
	local distance = 10 -- distance between the model and the character
	local pos = HRP.Position + (HRP.CFrame.LookVector)*distance
	
	model.Parent = workspace
	model:MoveTo(pos)
end)

Those aren’t errors they’re just warnings that you should declare stuff locally, also the localplayer property needs to be formatted like “LocalPlayer”. “game.ReplicatedStorage” also.

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")

local rs = game:GetService("ReplicatedStorage")
local model = rs:WaitForChild("Model") --change to name of model in replicated storage

local button = script.Parent

button.MouseButton1Click:Connect(function()
	model:PivotTo(hrp.CFrame * CFrame.new(-10, 4, 0))
	model.Parent = workspace
end)

It did work but only once and the script in the model stoped working can you help with these problems?

Did you get any errors in the script?

I did not get any errors in script

Define model as game.ReplicatedStorage.Model:CLone() instead.

I have the Same Problem Actually, I Was Working on Placer Tool That Spawns Model.

That’s simple. Use replicated storage. Get the model by using game:GetService(“ReplicatedStorage”) and clone it using :Clone() then set the position with Vector3.new(X,Y,Z) so altogether it should look something like this:

local model = game:GetService(“ReplicatedStorage”):Clone()
local position = Vector3.new(0,0,0) --your position

model.Parent = game.Workspace
model.Position = position --your variable

then link it to a click event like this:

game.Players.LocalPlayer.PlayerGUI.Button.Clicked:Connect(function()

–the code above here