I Can't Get the Player with a touched event and a """debounce"""

Sorry if my english isn’t very clear.

  1. What do you want to achieve? Keep it simple and clear!
    I want to create a tycoon system where you can get your tycoon only by touching the door.

  2. What is the issue? Include screenshots / videos if possible!
    I can’t get the Player, when I made a simpler script to claim the tycoon its worked but the player could get all the tycoons, so with another script I added a Bollean Value that starts with false and gets true when the player claim a tycoon, the problem is the game give the error “Index nil with Waitforchild…”

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I tried anothers methods of get the player with a touched event but that was useless, I am about 4 hours trying to write this only function (yes, I known that’s a lot of time for a simple function), here’s my code on the principal module Script.

function Tycoon:Init(player,Doro,text)
	local Player = game.Players:GetPlayerFromCharacter(player.Parent)
    local own = Player:WaitForChild("own",5)
	if not own then 
	self.Owner = player
	Doro.SurfaceGui.Claim.TextTransparency = 1
		text.Text = Player.DisplayName
		own = true
		else return end 
	end

on the script of the bollean value:

game.Players.PlayerAdded:Connect(function(player)
	local own = Instance.new("BoolValue")
	own.Parent = player
	own.Name = "own"
	own.Value = false
end)

the door’s script:

local Tycoon = require(game:GetService("ServerScriptService").General)
local doro =  script.Parent.Doro
local text = script.Parent.Parent.BillboardGui.TextLabel

Tycoon.new()

doro.Touched:Connect(function(player)
		Tycoon:Init(player,doro, text)
	   
end)

First of all, I suggest you do not use BoolValues parented to the Player because exploiters are able to change it.

As for a tycoon door, you can simply add an Attribute on the door and add a script inside the door:

local Players = game:GetService("Players")
local door = script.Parent

door.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid") then
 
    local player = Players:GetPlayerFromCharacter(hit.Parent)

     local owner = door:GetAttribute("Owner")

     if owner == nil then

           door:SetAttribute("Owner",player)
           door.Parent.BillboardGui.Text = player.Name

      end

end

end)
1 Like

It’s worked tysm, at the first I got some errors because the attribute was on the door and the setattribute(“own”,player) returned a error, but it was easy to solve, thank you!

1 Like