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," ingame.Workspace.Presets
, but how would I do this so it looks for the variable rather than an object named "d"?
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