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

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

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

✓ Accepted answer

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

1 comment

0

Thank you!

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