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

How to check for one person's data only?

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

✓ Accepted answer

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)

12 comments

0

Thanks! I didn't know everything else was unnecessary. I don't really know how to use tables that well.

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.

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.

0

I don't know what you're talking about because you never posted any of that.

0

I edited the script, the top one is the script inside the 1 star ball

0

edited answer

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.

0

EIther 7 seconds or i just have to keep touching it like 20 times for it to disappear

0

Nothing here is causing that to happen.

0

So then the script is deffective or Roblox is defective?

0

But whatever, Roblox sucks, I'll just accept your answer

0

Nothing here is defective. You haven't posted the thing that is wrong.

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