Spawn an item in front of player

I have a chat script that when a certain thing is said,

A picked item spawns right in front of the player.

This is the problem im stuck on because i do not know how to get it in front of the player. Any help is greatly appreciated. :+1:

3 Likes

you have to set its CFrame to for example :

YourObject.CFrame = HRP.CFrame + Vector3.new(2,0,0)
2 Likes
local Players = game:GetService("Players")
local Storage = game:GetService("ServerStorage")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Char)
		spawn(function()
			while true do
				task.wait(3)
				local item = Storage:FindFirstChild("ClassicSword"):Clone()
				item.Parent = workspace
				item.Handle.CFrame =Char.HumanoidRootPart.CFrame + Vector3.new(5,0,0)
			end
		end)
	end)
end)

or:

local Players = game:GetService("Players")
local Storage = game:GetService("ServerStorage")


Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Char)
		spawn(function()
			while true do
				task.wait(3)
				local item = Storage:FindFirstChild("ClassicSword"):Clone()
				item.Parent = workspace
				item.Handle.CFrame = Char.HumanoidRootPart.CFrame*CFrame.new(Vector3.new(5,0,0))
			end
		end)
	end)
end)

This would return you an error.

2 Likes

Does not seem to be doing anything at all, no errors.

 local Players = game:GetService(“Players”) 
local ServerStorage = game:GetService(“ServerStorage”) 

local item = ServerStorage.ChatSpawnItems.Cat 

Players.PlayerAdded:Connect(function(Player) 
Player.Chatted:Connect(function(Message) 
If Message == “/a cat” then 
Players.PlayerAdded:Connect(function() 
Player.CharacterAppearanceLoaded:Connect(function(Char) 
spawn(function() 
task.wait(3) 
Item.Parent = workspace 
Item.CFrame = Char.HumanoidRootPart.CFrame*Cframe.new(Vector3.new(5,0,0)) 
end) 
end) 
end) 

Also, its a model, not an actual tool.

since its a model this will work.
this will work for models/baseparts

YourObject:PivotTo(Char.HumanoidRootPart.CFrame + Vector3.new(5,0,0))
1 Like

nothing happens, still. i did what you said and nothing.

well, it works fine for me, can you show your updated code?

1 Like

All i did was change line 14, and replaced item.Cframe etc to yours.

1 Like
Item:PivotTo(Char.HumanoidRootPart.CFrame * CFrame.new(5,0,0)) 

Instead if PivotTo try MoveTo(Char.HumanoidRootPart.Position

1 Like

no need to use that since PivotTo just works fine.

MoveTo might work since it spawns on top of everything in it’s way, since PivotTo might be spawning a bit below the ground

Both of the methods dont even enter the model in workspace. Its not your ideas i think its that its not going in workspace.

did you do exactly like this?

Item:PivotTo(Char.HumanoidRootPart.CFrame * CFrame.new(5,0,0)) 

twice now! As i said its not that, its that the model isnt going in workspace period.

Try printing the model.
And also are you doing this on server or local script?

try removing the spawn function.

2 Likes

server script and thank you ill do that.

Wont print it. So that must be the issue somehow.

Still nothing, sorry it must be the model not going into workspace.