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

How can I get this to function properly?

Asked by 9 years ago

So this script was designed to function when the gui button is clicked (working) The player's torso is anchored until the player clicks the button (working) After the player clicks the gui button, a part is created, and positioned (working) When the player steps on the part created, a part is supposed to clone into the workspace, supposed to be anchored, and positioned (NOT WORKING)

local player = game.Players.LocalPlayer --You are using a local script so you can use LocalPlayer.

script.Parent.MouseButton1Down:connect(function()

                             script.Parent.Parent.Visible = false

local tutorial = Instance.new("Part",workspace)

tutorial.Name = "tutorial"

tutorial.CFrame = CFrame.new(Vector3.new(3.301, 0.7, 36.088))


    local g = Instance.new("Hint", workspace)
wait(.3)
g.Text = player.Name..", Step on the gray square behind you to begin tutorial!"

    wait()
player.Character.Torso.Anchored = false        

end)
function onTouched(part)
tutorial.OnTouched:connect(part)
local clone = Lighting.Sofa:Clone()
clone.Parent = workspace
    clone.Name = sofa1
sofa1:MoveTo(Vector3.new(3.301, 0.7, 36.088)) --Models don't have position. To move a model use :MoveTo(Vector3.new())
end


The thing is everything works up until the object from lighting is supposed to be cloned. I think the problem is on line 23 tutorial.OnTouched:connect(part)

I don't know how to fix it, I want the parts to clone from workspace when that part is touched.

1 answer

Log in to vote
0
Answered by 9 years ago

Line 23 should not be tutorial.OnTouched:connect(part) part is not the name of your function, onTouched is. part is whatever touched the tutorial. Plus you seem to not understand or at least confused yourself with connecting. This is how line 23 should actually appear: tutorial.Touched:connect(onTouched) I'm not sure of your hierarchy and how it's placed so if this does not work, check it your hierarchy.

So your code should look like this:

local player = game.Players.LocalPlayer --You are using a local script so you can use LocalPlayer.

script.Parent.MouseButton1Down:connect(function()

                             script.Parent.Parent.Visible = false

local tutorial = Instance.new("Part",workspace)

tutorial.Name = "tutorial"

tutorial.CFrame = CFrame.new(Vector3.new(3.301, 0.7, 36.088))


    local g = Instance.new("Hint", workspace)
wait(.3)
g.Text = player.Name..", Step on the gray square behind you to begin tutorial!"

    wait()
player.Character.Torso.Anchored = false        

end)
function onTouched(part)
local clone = Lighting.Sofa:Clone()
clone.Parent = workspace
    clone.Name = sofa1
sofa1:MoveTo(Vector3.new(3.301, 0.7, 36.088)) --Models don't have position. To move a model use :MoveTo(Vector3.new())
end

tutorial.Touched:connect(onTouched) -- This is how I see this way of making a function usually lain out. Now, maybe having this at 23 will still work, I'm not sure; you can test.

0
Still have a problem? Comment on this and tell me what your output is (If any) and check your Hierarchy! Then i'll help if what I said doesn't seem to work. alphawolvess 1784 — 9y
0
I tested it out just now, I didn't see any difference in how it worked. The cloning still didn't function. SmokeyIsSmoking 0 — 9y
0
Is tutorial inside of script? tutorial must be a part and inside the script for that way to work. Can you explain your Hierarchy? alphawolvess 1784 — 9y
0
Well the part is being created through instance.new so it's non-existing SmokeyIsSmoking 0 — 9y
Ad

Answer this question