Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does the campfire not spawn at the player?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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.

0
only problem is that now the campfire spawns on top of the characters head MasonTheCreeperYT3 74 — 6y
0
Ok let me edit to fix it SystemFormat 149 — 6y
0
k MasonTheCreeperYT3 74 — 6y
0
im not sure wants wrong the campfire still spawns on top of my head MasonTheCreeperYT3 74 — 6y
View all comments (2 more)
0
edited again lol SystemFormat 149 — 6y
0
lol it works now thanks MasonTheCreeperYT3 74 — 6y
Ad

Answer this question