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

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

Asked by 1 year ago

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

Log in to vote
1
Answered by 1 year ago

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) 
Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year ago
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) 
Log in to vote
0
Answered by 1 year ago
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

0
u just stool me answear >:( (jk) T3_MasterGamer 2189 — 1y
0
oops lol JmoneyPlayzOfficial 49 — 1y

Answer this question