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

What is wrong with this function?

So I've gotten help from multiple people on this, none of which have gotten past this part.

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

 		tut = Instance.new("Part",workspace)

		tut.Name = "tutorial"

		tut.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 to begin tutorial!"
		tut.Anchored = true
    wait(.3)
	player.Character.Torso.Anchored = false        
end)
---------------------------------------------------------------------------------------
function onTouched(part)
local character = part.Parent
local plr = game.Players:GetPlayerFromCharacter( character )

if plr then


local a = Instance.new('Message', workspace)
	player.Character.Torso.Anchored = true
		a.Text = "Tutorial Loading."
	wait(.5)
		a.Text = "Tutorial Loading.."
	wait(.5)
		a.Text = "Tutorial Loading..."

local clon = game.Lighting.Sofa:Clone()
	clon.Parent = game.Workspace
	clon:MoveTo(Vector3.new(3.301, 0.7, 36.088)) --Models don't have position. To move a model use :MoveTo(Vector3.new())
	wait(.2)
player.Character.Torso.Anchored = false
				end
			end
print '4'
	
 -- 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.


The problem begins at

function onTouched(part)
local character = part.Parent
local plr = game.Players:GetPlayerFromCharacter( character )

if plr then
--rest of script

The problem is, with the part that is created tut = Instance.new("Part", workspace), the rest of the script is supposed to function, like the cloning of the model in Lighting (i know, it should be ReplicatedStorage, but either work).

1 comment

0

at the bottom of the script add: script.Parent.Touched:connect(onTouched)

1 answer

Here you go!

function onTouched(part)
local character = part.Parent
local plr = game.Players:GetPlayerFromCharacter( character )

if plr then
--rest of script
<OBJECT>.Touched:connect(onTouched)--There we go!

1 comment

0

opps sorry LordDragon didn't see your Comment.

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