I feel like i’ve tried everything, but it just doesnt want to work.
Basically im trying to get the players name into an object value.
local debounce = false
local Owner = script.Parent.Owner
script.Parent.ClickDetector.MouseClick:Connect(function(hit)
if debounce == false then
debounce = true
print(hit.Name)
print(game.Players:GetPlayerFromCharacter(hit)) -- Where it returns nil
-- The rest of my simple code is here
debounce = false
end
end)
1 Like
Please read the documentation next time. ClickDetector.MouseClick
already returns the player, you don’t need GetPlayerFromCharacter
here.
Yeah but for Object Values, theyre funny and never work the way you’d expect.
What do you mean by this, and how are ObjectValues
related to this?
Im trying to set the players name as the value in an Object Value
Owner.Value = game.Players:GetPlayerFromCharacter(hit)
attempt to concatenate string with nil
ObjectValues hold Instances, not strings. I assume you just want the ObjectValue to hold the player, so you would use:
local debounce = false
local Owner = script.Parent.Owner
local objectValue = PATH_TO_OBJECTVALUE
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if debounce == false then
debounce = true
objectValue.Value = player
-- The rest of my simple code is here
debounce = false
end
end)
Try this.
local debounce = false
local Owner = script.Parent.Owner
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if debounce == false then
debounce = true
print(player.Name)
-- The rest of my simple code is here
debounce = false
end
end)
Hey, thanks, and i’ve finally figured it out now.
Owner.Value = hit
I swear I tried this, and before it didnt work. But yeah. I guess thats it.
Ive been up for 2 hours trying to get this to work and this whole time the answer was infront of me.
Its midnight now so I’m gonna go sleep.
well
the code:
print(game.Players:GetPlayerFromCharacter(hit)) – Where it returns nil
you only put the “hit” not the player that touched so it means thats nothing thats why it return nill because theres no parent to get from playercharacter so you need to put “hit.Parent” not “hit”