This code is supposed to spawn a part on the player when the tool activates, but no part is appearing, and there is no error.
debounce = false
local char = player.CharacterAdded:Wait()
local pos = char:GetPrimaryPartCFrame().p
local torsox = player.Character.LowerTorso.CFrame.x --the players torso x value
local torsoy = player.Character.LowerTorso.CFrame.y --the players torso y value
local torsoz = player.Character.LowerTorso.CFrame.z --the players torso z value
local function createPart(location)
local part = Instance.new("Part")
part.BrickColor = BrickColor.new("Brown")
part.CFrame = part.CFrame+Vector3.new(torsox, torsoy ,torsoz)
end
function equip()
if debounce == false then
debounce = true
script.Parent.Handle.Sound:Play() -- It would be here instead
createPart()
wait(4)
debounce = false
end
end
script.Parent.Equipped:Connect(equip)
From what I can tell, it likely has to do with the fact that you’re not parenting the part you create. After using Instance.new() (or while using it, as a second parameter), you should specify part.Parent
-- ServerScript inside of the Tool object
local debounce = false
local player = -- path to player
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild("LowerTorso")
local function SpawnPart()
local x = torso.CFrame.x
local y = torso.CFrame.y
local z = torso.CFrame.z
local part = Instance.new("Part")
part.BrickColor = BrickColor.new("Brown")
part.CFrame += Vector3.new(x, y, z)
part.Parent = workspace -- or wherever you want it to spawn
end
script.Parent.Equipped:Connect(function()
if not debounce then
debounce = true
script.Parent.Handle.Sound:Play()
SpawnPart()
wait(4)
debounce = false
end
end)