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

GUI button not working but nothing is marked wrong?

Asked by
RoyMer 301 Moderation Voter
9 years ago

This button when pressed should be decreasing 1 from the stage Value and adding 1 to the test Value, but it is not working yet there are no errors marked.

(ds is the datastore)

local player = game.Players.LocalPlayer
local test = player.ds.Test 
local stage = player.leaderstats.Stage.Value

DB = true
function Click()
if DB == true then
DB = false

stage.Value = stage.Value -1
wait(1)
test.Value = test.Value +1

end

wait(1) -- Time until button can be pressed again.
DB = true
end


script.Parent.MouseButton1Down:connect(Click)

1 answer

Log in to vote
0
Answered by
davness 376 Moderation Voter
9 years ago

Oops, you have an small typo on your script:

local player = game.Players.LocalPlayer
local test = player.ds.Test 
local stage = player.leaderstats.Stage -- here your error: You should connect a variable to an object and not to a property, i corrected it.

DB = true
function Click()
if DB == true then
DB = false

stage.Value = stage.Value -1
wait(1)
test.Value = test.Value +1 -- you were doing something like player.leaderstats.Stage.Value.Value - any sense?

end

wait(1) -- Time until button can be pressed again.
DB = true
end

script.Parent.MouseButton1Down:connect(Click)

Finnaly, to check if something really works, you can use the output

local player = game.Players.LocalPlayer
local test = player.ds.Test  -- on this case, test = 1
local stage = player.leaderstats.Stage -- on this case, stage = 10

DB = true
function Click()
if DB == true then
DB = false

print(stage.Value) -- will print 10
stage.Value = stage.Value -1
print(stage.Value) -- will print 9
wait(1)
print(test.Value) -- will print 1
test.Value = test.Value +1
print(test.Value) -- will print 2

end

wait(1)
DB = true
end

script.Parent.MouseButton1Down:connect(Click)

Hope I helped!

0
I did eventually become aware of that typo but still something is not working right, I'm using this datastore :/ http://www.roblox.com/DataStore-Leaderboard-item?id=160906730 RoyMer 301 — 9y
0
Got it to work, I'm not sure if I enabled API or if I moved line 2 and 3. Thanks though! RoyMer 301 — 9y
Ad

Answer this question