I am trying to make a game where you claim a plot of land and farm on it and the claiming part will not work for me. It gives me an error saying that locplayer is not a part of Players and this is my code...
local plotowner
local plot = script.Parent
local vacant = true
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
local locplayer = player.Name
end)
local function onPartTouched(otherPart)
if vacant == true then
-- Get the other part's parent
local partParent = otherPart.Parent
-- Look for a humanoid in the parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if Players.locplayer["HasPlot?"] == true then
print("ALREADY HAVE A PLOT!")
else
Players.locplayer["HasPlot?"] = true
print("PLOT HAS BEEN CLAIMED!")
vacant = false
end
end
end
end
plot.Touched:Connect(onPartTouched)

1 comment
otherpart.Parent is the players character if a player was the thing that touched it. So you would do GetPlayerFromCharacter. If you look it up it should show you how to use it