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

How to check for one person's data only?

Asked by 9 years ago

Basically I made dragon balls. I have DB1 - DB7 in the player data as bool value for each player. I'm trying to make it so if a player has the bool value to true, don't spawn the dragon ball. But my for loop is checking for EVERYONE if they all have it to true, don't spawn or else it does spawn. All I want is to make it so if 1 player has the bool value to true, it doesn't spawn that certain dragon ball.

Script inside dragon ball

local db = script.Parent
local debounce = true
function onTouch(hit)
    if debounce  then
    if hit.Parent:FindFirstChild("Humanoid") then
        debounce = true
        db:Destroy()
        local player = hit.Parent.Name
        game.Players[player].Data.DB1.Value = true
        debounce = false
        end
    end
end

db.Touched:connect(onTouch)

Script you gave me waffle:

while wait(1)do
    for i=1,7 do
        local rDB=true
        if not workspace:FindFirstChild(i.." Star")then
            for _,v in next,game.Players:GetPlayers()do
                if v.Data["DB"..i].Value then
                    rDB=false
                    break
                end
            end
        end
        if rDB then
            game.ServerStorage[i.." Star"]:Clone().Parent=workspace
        end
    end
end

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

In the while loop, you're calling DB1 and then DB2, etc. but DB1 is already an infinite loop, so the other ones are never going to run.

In DB1, you're calling rDB1 for every player whose DB1's value is false. You want to call rDB1 only if they are all false.

Your script is unnecessarily long and redundant. I've shortened it with a for loop and concatenation, and fixed those problems.

while wait(1)do
    for i=1,7 do
        if not workspace:FindFirstChild(i.." Star")then
            local rDB=true
            for _,v in next,game.Players:GetPlayers()do
                if v.Data["DB"..i].Value then
                    rDB=false
                    break
                end
            end
            if rDB then
                game.ServerStorage[i.." Star"]:Clone().Parent=workspace
            end
        end
    end
end

edit:

On line 7 the script is destroyed and the program is terminated. If you're going to destroy it, nothing can happen afterwards, so it should be the last thing.

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid")then
        game.Players[hit.Parent.Name].Data.DB1.Value=true
        script.Parent:Destroy()
    end
end)
0
Thanks! I didn't know everything else was unnecessary. I don't really know how to use tables that well. ByteInfinity 40 — 9y
0
The only table here is the list of players that you're iterating through. If their DB# is true, tell it to not clone. If it was never told to not clone, it clones. 1waffle1 2908 — 9y
0
It's not working exactly correct. Now i need to keep touching it for how many players are in the server to get it. I don't know what the problem is, or else do I need to add a debounce to it? Inside the DB script i mean for the "Touched" event. ByteInfinity 40 — 9y
0
I don't know what you're talking about because you never posted any of that. 1waffle1 2908 — 9y
View all comments (8 more)
0
I edited the script, the top one is the script inside the 1 star ball ByteInfinity 40 — 9y
0
edited answer 1waffle1 2908 — 9y
0
There is a problem with the script you gave me. When I touch it, it gives me the true value , but it takes like 7 seconds for the dragon ball to disappear. ByteInfinity 40 — 9y
0
EIther 7 seconds or i just have to keep touching it like 20 times for it to disappear ByteInfinity 40 — 9y
0
Nothing here is causing that to happen. 1waffle1 2908 — 9y
0
So then the script is deffective or Roblox is defective? ByteInfinity 40 — 9y
0
But whatever, Roblox sucks, I'll just accept your answer ByteInfinity 40 — 9y
0
Nothing here is defective. You haven't posted the thing that is wrong. 1waffle1 2908 — 9y
Ad

Answer this question