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

How to locate a variable?

Asked by
JJ_B 250 Moderation Voter
8 years ago

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"?

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

1 answer

Log in to vote
0
Answered by 8 years ago

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

Ad

Answer this question