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

How come the event wont be fired when a value isn't blank?

I'm trying to make it where if a value is NOT blank it will fire an event, but instead, it does nothing even tho the value isn't blank. I get no errors at all. What's the problem?

ButtonsFolder.PlayButton.MouseButton1Click:Connect(function()
	if not ValuesFolder.Class.Value == nil then
		ReplicatedStorage.Events.SpawnEvent:FireServer(ValuesFolder.Class.Value)
	else
		print("Please Select a Class")
	end
end)

2 comments

0

What's the ClassName of the instance?

0

StringValue2

1 answer

✓ Accepted answer

StringValue doesn't return nil even if it's empty. It will just return an empty string (""). Try this instead:

ButtonsFolder.PlayButton.MouseButton1Click:Connect(function()
    if ValuesFolder.Class.Value ~= "" then
        ReplicatedStorage.Events.SpawnEvent:FireServer(ValuesFolder.Class.Value)
    else
        print("Please Select a Class")
    end
end)

2 comments

0

For some reason it still fires the event even if the player doesn't have a class I get this error "Players.vincentthecat1.PlayerGui.MainGui.Scripts.ValuesReplacement:20: attempt to index nil with 'Value'"

0

Wait I forgot to delete not(I had to copy paste the ~= "")

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