Script will not work

Let’s jump to the issue:
I put a local script to test something. It would put the value of a StringValue to either “win” or “lose”, but neither show up! (Yes, I checked spelling, it is correct.)

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.WinLose.Value = "win" or "lose"
end)

Please help!
-Noodles

1 Like

Did you make sure that the string value WinLose is not nil? If it is that is your problem. Also I am unsure that it will randomly pick win or lose. With ‘or’, I’m pretty sure it always chooses the first one. To get around this use a table and use math.random to pick a number. Then get the win or lose from the table using that index.

1 Like

I will try this. 30charsssssss

The problem is you’re doing this in the local script,

  1. Rule, You cannot change any sort of values inside local scripts, unless it has a remote event/function

  2. You can add a math.Random to see if it’s a win or lose

script.Parent.MouseButton1Click:Connect(function()
    local k
    local number = math.Random(1,2)
    if number = 1 then
        k = "win"
    else
        k = "lose"
    end
    
    script.Parent.Parent.WinLose.Value = k
end)

But still, i would recommend you fire a remote event, because the values only change on the client and not on the server

1 Like

The only problem is this is an Investing Simulator, if I fire a remote, and somebody happens to buy it at the same time, they could get false results.

Do you recommend me make a system that it goes random every Wait(.5)?

Just add debounce when the player buys A

Ok 30charsssssssssssssssssssss

You’re putting a or for string values, which I think that only works for nil / false values.

If you get win or lose every 0.5 secconds, you can just make a script in serverscriptservice and when a player joins you always give them the value…