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

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

Asked by 2 years ago

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)
0
What's the ClassName of the instance? NotThatFamouss 605 — 2y
0
StringValue2 vincentthecat1 199 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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)
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'" vincentthecat1 199 — 2y
0
Wait I forgot to delete not(I had to copy paste the ~= "") vincentthecat1 199 — 2y
Ad

Answer this question