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

why can I not access a value from a player folder?

I have tried multiple different approaches and never have figured out why this is happening or what is wrong. it never says anything in the output either.

Script:

function color(player)
	local Color = player.DataFolder.GravelColor.Value
	if Color == 1 then
		script.Parent.BrickColor = BrickColor.new("Really red")
	elseif Color == 2 then
		script.Parent.BrickColor = BrickColor.new("Buttermilk")
	elseif Color == 3 then
		script.Parent.BrickColor = BrickColor.new("Cyan")
	end
end

while true do
	color()
	wait(.2)
end

2 comments

0

just add a game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Wait() while true do color(player) wait(.2) end end) or something

0

thanks it worked now

1 answer

✓ Accepted answer

You're not specifying the player when calling the function

function color(player)
    local Color = player.DataFolder.GravelColor.Value
    if Color == 1 then
        script.Parent.BrickColor = BrickColor.new("Really red")
    elseif Color == 2 then
        script.Parent.BrickColor = BrickColor.new("Buttermilk")
    elseif Color == 3 then
        script.Parent.BrickColor = BrickColor.new("Cyan")
    end
end

while true do
	color(game.Players.LocalPlayer)
	wait(.2)
end

4 comments

0

How should I specify the player?

0

If this is a local script, do colors(game.Players.LocalPlayer). If this is a server script, use game.Players.PlayerAdded:Connect(function(plr) and insert the while true do loop into the thread, then say color(plr)

0

should I put this in the while true loop? it is a local script

0

Ill edit my script so i can show you

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