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)
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)
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)
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?