Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does the campfire not spawn at the player?

I'm trying to make it so that the campfire spawns at the player but it always spawns somewhere else does anyone know how to fix this? This is in a local script because it's using a GUI.

local player = game.Players.LocalPlayer
local character = game.Players.LocalPlayer.Character
local Campfire = game.ReplicatedStorage.Campfire

script.Parent.MouseButton1Click:connect(function()
	if player.Sticks.Value >= 2 then
		if player.Stone.Value >= 1 then
			player.Stone.Value = player.Stone.Value -1
			player.Sticks.Value = player.Sticks.Value -2
			local ClonedCampfire = Campfire:Clone()
			ClonedCampfire.Parent = game.Workspace
			ClonedCampfire.Position = character.Position
		end
	end
end)

1 answer

✓ Accepted answer

You're trying to set the campfire's position to a model. Model's don't have a position value, but the things inside of the model do. You should notice that this creates an error on the developer console (press F9 in-game when you try to spawn the campfire)

local player = game:GetService("Players").LocalPlayer
local character = game:GetService("Players").LocalPlayer.Character
local Campfire = game:GetService("ReplicatedStorage"):WaitForChild("Campfire")

script.Parent.MouseButton1Click:Connect(function()
    if player.Sticks.Value >= 2 and player.Stone.Value >= 1 then
            player.Stone.Value = player.Stone.Value -1
            player.Sticks.Value = player.Sticks.Value -2
            local ClonedCampfire = Campfire:Clone()
            ClonedCampfire.Parent = workspace
            ClonedCampfire:MoveTo(Character:WaitForChild("HumanoidRootPart").Position + (Character:WaitForChild("HumanoidRootPart").CFrame.lookVector * 3)) 
    end
end)

You may notice that I used :MoveTo(), this is a function that allows you to move every part of a model with one function. You can read more about it here

In order to make it spawn in front of the player, you'll want to use CFrame.lookVector.

6 comments

0

only problem is that now the campfire spawns on top of the characters head

0

Ok let me edit to fix it

0

k

0

im not sure wants wrong the campfire still spawns on top of my head

0

edited again lol

0

lol it works now thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.