✓ Accepted answer
Hey there, a few things with this script:
- You're putting a Statement as a Event which doesn't work. You could: 1. Make it a normal event or 2. something.Event:Wait() which will wait until the event happens. (More explanation on wiki)
- When scripting notice how the word "math" changes colors, I believe that is enough of a signal to tell you not to write that as a Variable name, a better name would be something like
count
Ok, so how do you fix this script? First we write all the variables that may be used:
local plr = game.Player.LocalPlayer
local state = script.Parent.State
local count = 1
Ok, now what we want to do is make a function, this function will update the text. This may seem a bit advanced but it's basically a variable for a set of command. Let's called our function UpdateState()
local plr = game.Player.LocalPlayer
local state = script.Parent.State
local count = 1
local function UpdateState()
end
Now we want to input your if statements in. We also want to add elseif's these bad boys will help reduce your lines.
local plr = game.Player.LocalPlayer
local state = script.Parent.State
local count = 1
local function UpdateState()
if count == 1 then
state.Text = "Responding"
elseif count == 2 then
state.Text = 'OnStation'
elseif count == 3 then
state.Text = 'OnScene'
elseif count == 4 then
count = 1
end
end
Now let's do the following:
- Call the function so it runs
- Fix your events
local plr = game.Player.LocalPlayer
local state = script.Parent.State
local count = 1
local function UpdateState()
if count == 1 then
state.Text = "Responding"
elseif count == 2 then
state.Text = 'OnStation'
elseif count == 3 then
state.Text = 'OnScene'
elseif count == 4 then
count = 1
end
end
UpdateState()
script.Parent.Up.MouseButton1Down:Connect(function()
count = count + 1
print(count)
UpdateState()
end)
script.Parent.Down.MouseButton1Down:Connect(function()
count = count - 1
print(count)
UpdateState()
end)
A few notes:
- this script will WORK to a degree
- You will have an issue of people spamming the buttons
- you will have an issue of where count goes into the negatives
Now I will let you solve these on your own.
Hopefully, this helped.
Best of luck developer!
3 comments
Yes i am using Mousebutton1click but it don’t works
The only thing I can say is put the ifs in the script.Parent.MouseWhatever:connect(function() line.
I will try tommorow