Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Claimable pad nolonger claimable after the player has left?

Hello.

I have been recently working on a script that is used for players to claim an aquarium, and once they do it can't be claimed by others. With that, when the player who has claimed the pad leaves, it frees it. This does work, however it can't be reclaimed after the player has left. I have gotten help with this script before, but I am stuck again. This script is very close to being done, but it's not quite done yet. What I did was have a bool value in the pad, named IsClaimed, that turns to true when it's claimed, and when the player leaves, it turns off. Now that works, but, after the player left it doesn't seem to be able to be reclaimed.

Here is my script:

local Pad = script.Parent
local Debounce = false

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvents = ReplicatedStorage:WaitForChild("Remote Events (Main)")
local IsClaimed = Pad.Parent.IsClaimed

local Aquariums = workspace.Map.Aquariums

Pad.Touched:Connect(function(hit)
    if not (Debounce) then
        Debounce = true
    if IsClaimed.Value == true then return end
        else
        local Player = Players:GetPlayerFromCharacter(hit.Parent)
        local Character = Player.Character

        local ClaimedValue = Player.PlayerGui.AquariumClaimed

        if ClaimedValue.Value == true then
        else
            Aquariums.PlayerPad1:FindFirstChild("Name Tag").NameUI.Username.Text = hit.Parent.Name
            RemoteEvents.Data:FireClient(Player)
            script.Parent.Process.Disabled = false
            ClaimedValue.Value = true
            IsClaimed.Value = true
        end
        wait(1)
        Debounce = false
        if IsClaimed.Value == true then
            if Player then
                Players.PlayerRemoving:Connect(function(PlayerLeaving)
                    if PlayerLeaving == Player then
                        Aquariums.PlayerPad1:FindFirstChild("Name Tag").NameUI.Username.Text = "Not Claimed"
                        IsClaimed.Value = false        
                        print("Space is now cleared")
                    end
                end)
            end
        else
            return end
        end
end)

It's probably a bit messy and could be alot better but I do not know how to determine if it's claimed by someone other than using values. A player's owning an aquarium value and a claimed aquarium value.

I'm not sure what is causing this problem, and would like some help. Thanks!

1 answer

✓ Accepted answer

The issue I see is that you set Debounce to true and then never set it to false if the Pad is touched when it has an owner

Try replacing lines 12-16 with:

Pad.Touched:Connect(function(hit)
    if not Debounce then
        if IsClaimed.Value == false then
            Debounce = true
            --Make debounce true here instead
            --Run code
        end
    end
end)

1 comment

0

Thanks, that worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.