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

Why is my script displaying the lose screen instead of the win (Changed)?

PickV is the person who is picked/holding the object.

local RoundEndV = game.Lighting.Variables.HandleGameVariables.RoundEnd
local PickV = game.Lighting.Variables.ActiveGameVariables.Pick
local localPlayerN = game.Players.LocalPlayer.Name

RoundEndV.Changed:Connect(function()
	if RoundEndV.Value == true then
		print(localPlayerN) -- For Testing
		print(PickV.Value) -- For Testing
		
		if localPlayerN == PickV then
			script.Parent.RoundWin.Visible = true
			print("Round Win")
		elseif localPlayerN ~= PickV then
			script.Parent.RoundLose.Visible = true
			print("Round Lose")
		end
	end
end)

I'm not sure why my script is showing the lose screen instead of the win screen. When I do my tests the two prints are the same value... I hope you can help me, I have posted this before but my problem is slightly different.

6 comments

0

The script is a local script in a gui.

0

What kind of data do the Values hold? The name? The player object itself? If they're not the same type, they'll never be equal.

0

My script is saying if the player's name is the same as the winner's then the gui will say "you won".

0

The values hold string values. One is the player's name and the other is a string value. Do I need to use a different kind of variable?

0

If the values hold strings too, make sure they don't have extra spaces or anything, then. Print their length. Something is fishy here if they actually show you the "same" value but actually aren't.

0

move the variables into replicated storage. Replicated storage was created for a reason

1 answer

✓ Accepted answer

u have to use .Value for values. example:

local RoundEndV = game.Lighting.Variables.HandleGameVariables.RoundEnd
local PickV = game.Lighting.Variables.ActiveGameVariables.Pick.Value--changed to value.
local localPlayerN = game.Players.LocalPlayer.Name

RoundEndV.Changed:Connect(function()
    if RoundEndV.Value == true then
        print(localPlayerN) -- For Testing
        print(PickV) -- For Testing

        if localPlayerN == PickV then
            script.Parent.RoundWin.Visible = true
            print("Round Win")
        elseif localPlayerN ~= PickV then
            script.Parent.RoundLose.Visible = true
            print("Round Lose")
        end
    end
end)

2 comments

0

omg thank you so much! I didn't realize that tiny error!

0

np

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