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

[Repost] How can I check if an user has something in his model located in Workspace?

Asked by
Kegani 31
6 years ago

Hello

I am currently trying to make a tracker for my Hunger Games group which is currently only obtainable with a morph giver thing.

With this tracker, I am trying to make it so I can use a GUI to get all status about the player (health, dead/alive, etc..).

However, I'm lost. I'm using a value that contains the text input here (http://prntscr.com/inu5y5) and I'm trying to get the script to locate the user in Workspace by using the text I put in the TextBox.

I've also tried using the PlayerAdded and CharacterAdded events, in vain.

Here is my script:

function onClick(noot)
    local val = script.Parent.Parent.TextBox.Value.Value
    local text = script.Parent.Parent.TextBox
    val = text.Text
    local tracker = game.Workspace.val:findFirstChild("Arm1")
    if tracker == nil then
        script.Parent.Parent.error.BackgroundTransparency = 0.5
        script.Parent.Parent.error.TextTransparency = 0
    end
end

script.Parent.MouseButton1Click:connect(onClick)

Arm1 is the tracker. Here's where's everything is located: http://prntscr.com/inu6qm

I'm not asking to be spoonfed, but I'm honestly lost. I'd appreciate some help so I can finally understand. Thanks!

1 answer

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

When you set a value instance's value to a variable, you cannot alter it through that variable. So instead of doing something like this:

local val = NumberValue.Value
val = val + 5

You have to do something like this:

local val = NumberValue
val.Value = val.Value + 5

As for searching for the character, you can use FindFirstChild. For example, you can do something like this using Players, and get the player's character through their Player:

local plr = game.Players:FindFirstChild(val.Value)
if plr and plr.Character and plr.Character:FindFirstChild("Arm1") then
    --has tracker
else
    --plr doesnt exist/player doesnt have tracker
end
0
Thank you! Kegani 31 — 6y
Ad

Answer this question