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

Why is my code to spawn an entity by clicking on a gui button not work?

Anybody help me with this? i'm suffering over here, just errors all the time.

function leftClick()

	script.Parent.MouseButton1Click:Connect(leftClick)	
	local NPC = game.ReplicatedStorage.angrymunci["NextbotV1.5"]:Clone()
	NPC.SetPrimaryPartCFrame(15.391, 84.829, -150.20)
	NPC.Parent = game.Workspace.bots

end

3 answers

✓ Accepted answer

First of all, when using methods like SetPrimaryPartCFrame(), use colons instead of dots. If you want to use dots, you can add the instance you're using the method with as the first parameter, but colon is way more recommended than that.

Second, when setting a CFrame, make sure to make the 3 numbers a CFrame by using CFrame.new() and inside the parentheses you put the 3 numbers.

And lastly, connect the function outside the function itself and not inside.

local function leftClick()
	local NPC = game.ReplicatedStorage.angrymunci["NextbotV1.5"]:Clone()
	NPC:PivotTo(CFrame.new(15.391, 84.829, -150.20))
	NPC.Parent = game.Workspace.bots
end
script.Parent.MouseButton1Click:Connect(leftClick) 
function leftClick()
local NPC = game.ReplicatedStorage.angrymunci["NextbotV1.5"]:Clone()   NPC.SetPrimaryPartCFrame(15.391, 84.829, -150.20)
NPC.Parent = game.Workspace.bots
end
script.Parent.MouseButton1Click:Connect(leftClick) 
function leftClick()
    local NPC = game.ReplicatedStorage.angrymunci["NextbotV1.5"]:Clone()
    NPC.PrimaryPart = NPC:FindFirstChild("Torso")
    NPC.PrimaryPart.CFrame = CFrame.new(15.391, 84.829, -150.20)
    NPC.Parent = game.Workspace.bots
end

script.Parent.MouseButton1Click:Connect(leftClick)

im not good at scripting so this might not work

2 comments

0

u just stool me answear >:( (jk)

0

oops lol

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