Hello! I'm making an obby and I have a gamepass which gives you "easy mode" which grants the player invincibility to all kill parts, and it worked! However, when I added a button in the gui to toggle easy mode, it stopped working.
The kill part script determines whether or not to teleport the player back to their checkpoint based on their bool value.
local debounce = false
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local tp = workspace.Stages[player.leaderstats.Stage.Value]
local char = hit.Parent
if player.Easy.Value == false then -- checks if player owns gamepass
if debounce == false then
debounce = true
if char:FindFirstChild("Humanoid") then
char:moveTo(tp.Position + Vector3.new(0,10,0))
wait(1)
end
debounce = false
end
end
end)
Two different scripts checks the player for ownership of the gamepass, or if they bought the gamepass ingame. If they do own it then it changes the player's Toggle bool value to true.
The local script in the toggle button then checks the player if that bool value is true, where it then changes the Easy bool value to either true or false.
local Color = script.Parent.Parent
local Button = script.Parent
local Toggle2 = false
Button.MouseButton1Up:Connect(function()
if Toggle2 == true then -- checks if player enabled Easy Mode
Toggle2 = false
game.Players.LocalPlayer.Easy.Value = false --disables Easy Mode
Color.BackgroundColor3 = Color3.new(255/255, 82/255, 82/255)
Button.Text = "Enable Easy Mode"
elseif game.Players.LocalPlayer.Toggle.Value == true then
game.Players.LocalPlayer.Easy.Value = true --enables Easy Mode
Color.BackgroundColor3 = Color3.new(85/255, 255/255, 127/255)
Button.Text = "Disable Easy Mode"
Toggle2 = true
else
game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,9211899)
end
end)
I created a part which prints the player's Easy value and even if the value was true it would still print 'false' and comes up with an error "attempt to index nil with 'Easy'". I don't understand why this happens.

1 comment
You will need an event that fires when you press the gui button, as that is a local script, so the server detects no change in value. This may help you: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events