Basically, I have a part you step on and it opens a GUI that gives them a Daily reward, the first time it works, but the second time it does not open but it gives the value of the daily reward. Why is this?
local debounce = false
function getPlayer(humanoid)
local players = game.Players:children()
for i = 1, #players do
if players[i].Character.Humanoid == humanoid then return players[i] end
end
return nil
end
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if (human ~= nil) and debounce == false then
debounce = true
local player = getPlayer(human)
if (player == nil) then return end
if player.DailyReward.Value == false then
script.Parent:clone().Parent = player.PlayerGui
wait(3)
debounce = false
player.PlayerGui.OnTouchGui.DWFrame.Visible = false
wait()
player.DailyReward.Value = true
debounce = false
if player.DailyReward.Value == true then
player.PlayerGui.OnTouchGui.DWFrame.Visible = true
end
end
end
end
script.Parent.Parent.Touched:Connect(onTouch)
The script below gives players the Daily Reward.
local currency = "Coins"
local amnt = 10
debounce = false
function onTouch(hit)
if hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == false then
if game.Players:findFirstChild(hit.Parent.Name) ~= nil then
local ThisPlayer = game.Players:findFirstChild(hit.Parent.Name)
local val = ThisPlayer.DailyReward.Value
ThisPlayer.Stats:findFirstChild(currency).Value = ThisPlayer.Stats:findFirstChild(currency).Value + amnt
script.Parent.Transparency = 1
script.Parent.CanCollide = false
val = true
debounce = true
wait(5) -- change to 86,4000 just for testing purposes
script.Parent.Transparency = 1
script.Parent.CanCollide = false
val = false
debounce = false
end
end
end
script.Parent.Touched:connect(onTouch)

1 comment
Nice free model