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

[SOLVED] How to use Object as String?

mouse.Button1Down:Connect(function()
	if mouse.Target.Parent:FindFirstChild("Humanoid") then
		local arrestee = mouse.Target.Parent
		print(arrestee)
		local arrested = game.Players[arrestee]
		if arrested["TeamColor"] == BrickColor.new("Teal") or arrested["Settings"].innocent.Value == true then
			print("innocent")
		else
			game.ReplicatedStorage.Arrest:FireServer(arrestee)
		end
	end
end)

I am trying to us arrestee as a string, anyway to do that?

Edit: I solved the issue by putting the team checker part to a script:

if mouse.Target.Parent:FindFirstChild("Humanoid") then
		local arrestee = mouse.Target.Parent
		print(arrestee)
		game.ReplicatedStorage.Arrest:FireServer(arrestee)

1 answer

✓ Accepted answer

you would use .Name

mouse.Button1Down:Connect(function()
    if mouse.Target.Parent:FindFirstChild("Humanoid") then
        local arrestee = mouse.Target.Parent
        print(arrestee.Name)
        local arrested = game.Players[arrestee.Name]
        if arrested["TeamColor"] == BrickColor.new("Teal") or arrested["Settings"].innocent.Value == true then
            print("innocent")
        else
            game.ReplicatedStorage.Arrest:FireServer(arrestee)
        end
    end
end)

6 comments

0

It didnt work

0

What error did you get?

0

Unable to cast value to object

0

What line?

0

Still gonna accept your answer since it solved the problem on my other script and you are the only one helped

0

5th line and 6th line

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