I’m trying to make a command where you type something in the chat and an object spawns on top of you. I’m wondering how I can spawn the object above the player’s current position.
You can use the Players service to get the Player object, then with that player object, you can get the position of their character by doing:
local position = player.Character.HumanoidRootPart.Position
however you will want to first check if their character exists before attempting to get the HRP.
Then if you want to position the object above their head, you can add 10 studs to the position:
object.Position = position + Vector3.new(0,10,0)
so like this?
local plr = game.Players.LocalPlayer
local frog = game.ReplicatedStorage.FrogMesh
local position = plr.Character.HumanoidRootPart.Position
plr.Chatted:Connect(function(msg)
if msg == "!frog" then
frog.Parent = Workspace
frog.Position = position + Vector3,new(0,10,0)
print("spawned")
else
print("Didn't spawn")
end
end)
@Mikzul are you able to help? I’ve seen you do something similar and was wondering if you could give some info on what i should do
this is pretty much it
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local hmr = character:WaitForChild("HumanoidRootPart")
local frog = game.ReplicatedStorage.FrogMesh
plr.Chatted:Connect(function(msg)
if msg == "!frog" then
local frogClone = frog:Clone()
frogClone.Parent = workspace
frogClone.CFrame = hmr.CFrame
print("Spawned!")
else
print("Didn't spawn.")
end
end)
You were nearly there, I just made a few changes, when referencing workspace if you use a capital “W” you’ll need to use “game.Workspace” if you use a lowercase “w” then you can simply use “workspace”.
Gosh I didn’t know that I was so close! Thank you everyone!
Vector3,new(0,10,0)
You also had a comma here which would need to be a dot but I removed that bit.
Vector3.new(0,10,0)
Yup I just noticed while I added that thank you