What do you want to achieve? Keep it simple and clear!
I want the script while cycle to work fine. And not give me problems, so i can continue scripting my game.
What is the issue? Include screenshots / videos if possible!
The script tells me that the tag variable is nill, while it should have the player name in it.
I double checked to see if i made the variable tag path right, and it is.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried writing it in other ways. By checking with an if before the other to see if the tag was nill or not. And it actually wasn’t cause it got into the if. But the following line keeps on giving me problems:
if Tag.Value ~= player.Name then
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
script.Parent.MouseButton1Click:Connect(function(player)
local found = "false"
local number = 1
while found == "false" do
local Tag = game.Workspace:FindFirstChild("Tycoon" .. number).Values.PlayerName
if Tag.Value ~= player.Name then
number += 1
else
found = "true"
end
end
end)
The problem isn’t the Tag.Value. If you’re getting the error Attempt to index nil with 'Name', in this case it means that your player variable is nil, because player is what you’re trying to index with ‘Name’.
The problem is that you’re trying to get the player from a parameter, but no parameter is passed into MouseButton1Click, so it will just be nil.
GUI clicks are handled locally for each player, so what you need to do is simply set the player variable using local player = game.Players.LocalPlayer.
MouseButton1Click does not pass the player. You would need to get the player a different way. If this is a local script, use game.Players.LocalPlayer, otherwise, use script:FindFirstAncestorOfClass("Player"). If the UI is not in a player, then something is wrong with your code.
You can’t send any info with built in functions, only if you call them yourself. So `MouseButton1Click:Connect()’ has no parameters other than the defaults. You can’t chose to send the player along because it won’t arrive there because it is not a default function parameter.
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local found = false
local number = 1
while found == false do
local Tag = game.Workspace:FindFirstChild("Tycoon" .. number).Values.PlayerName
if Tag.Value ~= player.Name then
number += 1
else
found = true
end
end
end)