I want to find the game player with the workspace player ID and put it in the variable. What should I do?

I want to find the game player with the workspace player ID and put it in the variable. What should I do?

local Enabled = true
local Player = game:GetService("Players")





local function TagHumanoid(humanoid, player)
	local creator_tag = Instance.new("ObjectValue")
	local occupantHumanoid = script.Parent.Parent.Parent.Parent.DriveSeat.Occupant
	local PlayerId = occupantHumanoid.Parent
	
	creator_tag.Value = player
	creator_tag.Name = "creator"
	creator_tag.Parent = humanoid
	creator_tag.Value = PlayerId      <------A game to put in here.You must find the player value.

	
end

local function UntagHumanoid(humanoid)
	if humanoid ~= nil then
		local tag = humanoid:findFirstChild("creator")
		if tag ~= nil then
			tag.Parent = nil
		end
	end
end

script.Parent.Touched:Connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	local plr = game:GetService("Players")
	if hit.Parent:FindFirstChild("Humanoid") and Enabled then  --부딪힌 상대 데미지 입는양
		Enabled = false
		if script.Hit.Value == false then

			script.Hit.Value = true 

		
			local number1 = math.floor(0.5 * script.Parent.AssemblyLinearVelocity.Magnitude)

			local hum = hit.Parent:FindFirstChild("Humanoid")

			hum.Health = hum.Health - number1
			TagHumanoid(Humanoid, plr)
			
		
			script.Hit.Value = false
			wait(2)
			Enabled = true
			UntagHumanoid(Humanoid)
		end
		
	end

end)




I’m not entirely sure what you mean, but you can get a player from their ID like this:

game:GetService('Players'):GetPlayerByUserId(UserId)

You can get their character just by adding .Character at the end:

game:GetService('Players'):GetPlayerByUserId(UserId).Character

You can get a player’s Character ID by doing:

game:GetService('Players'):GetPlayerFromCharacter(character)

Sorry, I am not good at English.

Look at this.

If I understand correctly, you’ll want this:

local PlayerId = Player:GetPlayerFromCharacter(occupantHumanoid.Parent).UserId

In:

local Enabled = true
local Player = game:GetService("Players")

function TagHumanoid(humanoid, player)
	local creator_tag = Instance.new("ObjectValue")
	local occupantHumanoid = script.Parent.Parent.Parent.Parent.DriveSeat.Occupant
	local PlayerId = Player:GetPlayerFromCharacter(occupantHumanoid.Parent).UserId

	creator_tag.Value = player
	creator_tag.Name = "creator"
	creator_tag.Parent = humanoid
	creator_tag.Value = PlayerId --      <------A game to put in here.You must find the player value.
end

local function UntagHumanoid(humanoid)
	if humanoid then
		local tag = humanoid:findFirstChild("creator")
		if tag then
			tag.Parent = nil
		end
	end
end

script.Parent.Touched:Connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	if hit.Parent:FindFirstChild("Humanoid") and Enabled then  --부딪힌 상대 데미지 입는양
		Enabled = false
		if not script.Hit.Value then
			script.Hit.Value = true 
			local number1 = math.floor(0.5 * script.Parent.AssemblyLinearVelocity.Magnitude)
			local hum = hit.Parent:FindFirstChild("Humanoid")
			hum.Health = hum.Health - number1
			TagHumanoid(Humanoid, Player)
			script.Hit.Value = false
			task.wait(2)
			Enabled = true
			UntagHumanoid(Humanoid)
		end
	end
end)

Thank you, but it doesn’t work. If you hit it like this,
The constructor inside the humanoid is not deleted.

Are there any errors? Does script.Hit exist? If everything exists, the code looks like it should work fine.

This probably won’t fix anything, but I’ve made a few more edits to your existing script (such as removing redundancies):

Code
local Enabled = true
local Player = game:GetService("Players")

function TagHumanoid(humanoid, player)
	local creator_tag = Instance.new("ObjectValue")
	local occupantHumanoid = script.Parent.Parent.Parent.Parent.DriveSeat.Occupant
	local PlayerId = Player:GetPlayerFromCharacter(occupantHumanoid.Parent).UserId

	creator_tag.Value = player
	creator_tag.Name = "creator"
	creator_tag.Parent = humanoid
	creator_tag.Value = PlayerId --      <------A game to put in here.You must find the player value.
	
	creator_tag,occupantHumanoid,humanoid,player = nil,nil,nil,nil
end

local function UntagHumanoid(humanoid)
	if humanoid then
		local tag = humanoid:FindFirstChild("creator")
		if tag then
			tag:Destroy()
			tag = nil
		end
		humanoid = nil
	end
end

script.Parent.Touched:Connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	if Humanoid and Enabled then  --부딪힌 상대 데미지 입는양
		Enabled = false
		if not script.Hit.Value then
			script.Hit.Value = true 
			local number1 = math.floor(0.5 * script.Parent.AssemblyLinearVelocity.Magnitude)
			Humanoid.Health -= number1
			TagHumanoid(Humanoid, Player)
			script.Hit.Value = false
			task.wait(2)
			UntagHumanoid(Humanoid)
		end
		Enabled = true
	end
	Humanoid = nil
end)

Thank you very much for your effort.

However, the problem is that the player ID must be in the creator_tag.Value Game.Player ID (Player)
If you enter the code you created, the value will be 0.

The first code I created is the Player ID is the Workspace Model ID.That’s why the leaderboard kill score doesn’t go up.


Ah, I think I see what the issue is then. Just remove the .UserId part from local PlayerId = Player:GetPlayerFromCharacter(occupantHumanoid.Parent).

Although I also see that you’re setting the creator_tag's Value twice. The first to player and then to the seat occupant. Is there any reason for that?

1 Like

Thank you, thank you, thank you, it works very well.

Creator_tag.value input 2 is a mistake because I was tired from working at dawn. I erased it earlier.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.