What trodex said above. You are getting the players index from the playerservice, but you must retrieve the value to set the BoolValue inside them. (ignore the other reply, I misunderstood the use of the PlayersService for a second)
@Prototrode's post is the solution. Just adding on, in the touched connection add a hit parameter to your function then use the hit variable (it’s set to the part that got hit) to get the character, then use the character to get the player.
Edit:
Here is an example:
local Players = game:GetService("Players")
game.Workspace.CandyIslandLock.Touched:Connect(function(hit)
local hit.Parent = character
--... get player etc.
player.Islands.CandyIsland.Value = true
game.StarterGui.IslandUnlocked.TextLabel.Visible = true
game.StarterGui.IslandUnlocked.TextLabel.Text = "Candy Island Unlocked"
wait(3)
game.StarterGui.IslandUnlocked.TextLabel.Visible = false
end)
Set the code up so that the players character is retrieved when they touch the CandyIslandLock, and from this you can get the actual player whom contains the BoolValue that you are wanting to change. (And then set the value)
game.Workspace.CandyIslandLock.Touched:Connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
local player = h.Parent:GetPlayerFromCharacter("Player")
player.Islands.CandyIsland.Value = true
game.StarterGui.IslandUnlocked.TextLabel.Visible = true
game.StarterGui.IslandUnlocked.TextLabel.Text = "Candy Island Unlocked"
wait(3)
game.StarterGui.IslandUnlocked.TextLabel.Visible = false
end
end)
local players = game:GetService("Players")
local candyPart = workspace:WaitForChild("CandyIslandLock")
players.PlayerAdded:Connect(function(player)
local Islands = Instance.new("Folder")
Islands.Name = "Islands"
Islands.Parent = player
local CandyIsland = Instance.new("BoolValue")
CandyIsland.Name = "CandyIsland"
CandyIsland.Value = false
CandyIsland.Parent = Islands
end)
candyPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
player.Islands.CandyIsland.Value = true
local playerGui = player.PlayerGui
local islandUnlocked = playerGui.IslandUnlocked
local candyLabel = islandUnlocked.TextLabel
candyLabel.Visible = true
candyLabel.Text = "Candy Island Unlocked!"
task.wait(5)
candyLabel.Visible = false
end
end
end)