Teleport a dummy to the player from ServerStorage

Hi there!
I wanted to make an admin panel for my game, and wanted to make it so that when i click a button, it teleports a dummy out of ServerStorage to a few studs in front of the player.

However, due to my limited scripting ability, i did not really know how to start. I tried to make a script, but could not think of how to do it.

As far as i am concerned, there is not much on the developer hub, nor is there a youtube tutorial.
If anyone can help put me on the right track, then that would be amazing!

2 Likes

Greetings!

So this is fairly simple to do. First, we’ll need to set up an Remote Event and store that in ReplicatedStorage. Then, create a script in ServerScriptService and then input the following code:

  local some_dummy = game.ServerStorage:WaitForChild("DUMMY!")
 game.ReplicatedStorage:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(player)
         local new_dummy = some_dummy:Clone()
         new_dummy.Parent = game.Workspace
         new_dummy:MakeJoints()
         local pos = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5)
         new_dummy:MoveTo(pos.p)
 end)

Then we’ll set up a script in the button in the client’s UI, and input the following code:

  local db
  local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
  script.Parent.MouseButton1Down:Connect(function()
      if not db then
           db = true
            event:FireServer()
            wait(3)
            db = false
          end
   end)

This should roughly be what you’re looking for. I may have forgotten the correct coordinates for spawning an object in front of another, so you might have to tweak the CFrame coordinate I’ve put in. I thought a Z of 5 was correct, if it isn’t it might have to be negative. Anywho, hope this helps!

2 Likes

So, I’d use a TextButton for the admin pannel and I’d use a RemoteEvent.
They’ll be 2 scripts, a Script in ServerScriptService and a LocalScript inside the TextButton.
Also make sure the Dummy has a PrimaryPart set.

On MouseButton1Click of that Button Connect and fire the Remote Event (:FireServer())

Connect OnServerEvent of that RemoteEvent in the Script, remember that the first parameter is the player who fired - you can use this for referencing the player.

Now call :Clone() upon the dummy, parent it to workspace and call :SetPrimaryPartCFrame() upon the model - give it a CFrame of probably:

player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-3) * CFrame.Angles(0,  math.rad(180), 0)

The CFrame.new(0,0,-3) gives it a forward offset of 3 and the CFrame.Angles(0, math.rad(180), 0) turns it around to face the player.

Good luck!

1 Like

Thank you so much!
It works!
Hope you have a good day

2 Likes