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

How to locate a variable?

The question explains it badly, but I have a script where it looks for a certain part in Workspace, but it needs to use a variable to find it, rather than just naming it.

script.Parent.MouseButton1Down:connect(function()
	local d = script.Parent.loc.Value
	local s = Instance.new("Sound")
	s.SoundId = "rbxasset://138811664"
	s.Parent = game.Players.LocalPlayer.Character.Torso
	s:Play()
	game.Players.LocalPlayer.Character.Torso.CFrame = game.Workspace.Presets.d.CFrame + Vector3.new(0,4,0)
	wait(2)
	s:destroy()
end)

In this instance I'm looking for "d," in game.Workspace.Presets, but how would I do this so it looks for the variable rather than an object named "d"?

1 comment

0

If you mean look for the Part that the Value's value is, game.Workspace.Presents:FindFirstChild(script.Parent.loc.Value)

1 answer

For this, you need to use a more flexible way of using the hierarchy To do this, you can use brackets

game.Players.LocalPLayer.Character.Torso.CFrame = workspace.Presents[d].CFrame + Vector3.new(0,4,0)

By just keeping a dot, Roblox is actually looking for an object named d

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