I'm making a script for player ownership where only the player who owns an object can interact with it. Here's my script:
UIS.InputChanged:Connect(function(input)
local player = game.Players.LocalPlayer
local openInfo = player:WaitForChild("PlayerGui"):WaitForChild("E_to_open_box")
local ownerGui = player:WaitForChild("PlayerGui"):WaitForChild("OwnerGui"):WaitForChild("Frame")
local mouse = player:GetMouse()
local target = mouse.Target
if target then
if target:FindFirstChild("Box") then
if target.PlayerOwner.Value == player.UserId then
local distance = player:DistanceFromCharacter(target.Position)
if distance <= 30 then
openInfo.Enabled = true
openInfo.Adornee = target
ownerGui.Visible = false
end
else
ownerGui.PlayerOwner.Text = target.PlayerName.Value
ownerGui.Visible = true
end
else
openInfo.Enabled = false
openInfo.Adornee = nil
ownerGui.Visible = false
end
end
end)
PlayerOwner is a StringValue, should I change that to an IntValue? When I print both the PlayerOwner.Value and the player.UserId, they are the same, yet the if target.PlayerOwner.Value == player.UserId then isn't working.

5 comments
Forgot to mention but this is also a LocalScript inside StarterPlayerScripts.
Use an ObjectValue and change the value of it to the player, then make sure ObjectValue.Value == player
That didn't work, I still got the same result.
if it's a string value, you can do tostring(player.UserId) -> which converts the players id to a stringvalue, so it can be compared
oSyrical that worked thanks!