To spawn the model infront of the person using the tool
You forgot to set the cloneâs primary part. clone.PrimaryPart = PrimePart (EDIT: make sure to change the name of one of the parts in the model to âPrimePartâ or a name of ur choosing)
Instead, why not just the HumanoidRootPart
CFrame, and use LookVector
to spawn it in front of the player?
When you make a clone, the PrimaryPart stays.
Ive set the primary part for the model i want to spawn.
I dont know how to use LookVector. As i said im a beginner scripter
Here is your updated code:
local cybertruck = game.ServerStorage.ModelSpawnerFolder.Cybertruck
local button = script.Parent
local gui = script.Parent.Parent.Parent.Parent
local targetpart = game.ServerStorage.DevTools.SpawnerTool.TargetPart
local cooldown = false
button.MouseButton1Click:Connect(function()
if cooldown == false then
cooldown = true
local clone = game.ServerStorage.ModelSpawnerFolder.Cybertruck:Clone()
local cframe = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame -- Change this, this is gross
clone:SetPrimaryPartCFrame(cframe + cframe.LookVector * 10)
clone.Parent = game.Workspace
button.Text = "Cooldown for 2 seconds.."
wait(2)
cooldown = false
button.Text = "CyberTruck"
end
end)
It doesnt work for some reason i click the button but it doesnt do anything doesnt even say cooldown
What is the output saying? (30)
Nothing somehow im clicking the button but nothing is happening
Do some printing between lines. What is the last to print?
Wait i found the problem i deleted the target part and the varible is still there so it stopped there trying to find the target part
Ok now that the script is fixed i click the button gives me this error
13:24:47.402 Players.spydercam500.PlayerGui.SpawnToolGui.MainFrame.ScrollingFrame.CybertruckButton.Script:9: attempt to index nil with âCharacterâ - Server - Script:9
@iGottic
I just realized youâre doing the UI on the server side of the code. At this point, itâs beyond proper fixing, only random patches.
You can work around it though with this code:
local cybertruck = game.ServerStorage.ModelSpawnerFolder.Cybertruck
local button = script.Parent
local gui = script.Parent.Parent.Parent.Parent
local targetpart = game.ServerStorage.DevTools.SpawnerTool.TargetPart
local cooldown = false
button.MouseButton1Click:Connect(function()
if cooldown == false then
cooldown = true
local clone = game.ServerStorage.ModelSpawnerFolder.Cybertruck:Clone()
local cframe = gui:FindFirstAncestorOfClass("Player").Character.HumanoidRootPart.CFrame -- Change this, this is gross
clone:SetPrimaryPartCFrame(cframe + cframe.LookVector * 10)
clone.Parent = game.Workspace
button.Text = "Cooldown for 2 seconds.."
wait(2)
cooldown = false
button.Text = "CyberTruck"
end
end)
:MoveTo() uses Vector3 to move the model
but the models needs a PrimaryPart