Im trying to make a tagging system for a sword fighting game but i get a problem saying that its not a string value when i try to give the player a tag value i put a string value which is the player who hit the other person here is my code:
function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if (h~=nil) then local thisplr = game.Players:findFirstChild(h.Parent.Name) print(thisplr) print("name found") if (thisplr~=nil) then local stats = thisplr:findFirstChild("playerdata") print("leaderstats found") if (stats~=nil) then local score = stats:findFirstChild("Tagged") print("value found") if (score~=nil) then local plrname = script.Parent.Parent.Name game.Players[thisplr].playerdata.Tagged.Value = plrname print("tagged") end end end end end script.Parent.Handle.Touched:connect(onTouched)
change these locals to the ones i state here (I will explain them):
local thisplr = game.Player:GetPlayerFromCharacter(part.Parent) -- if a player touches the part with one of their limbs, and the parent is a character, then it will get the player from the character (as character is a parent of player).
thisplr cannot find the player simply by doing game.Players:findFirstChild(h.Parent.Name)
. It may find the player's name, but it's not the best way to go about it. Just do GetPlayerFromCharacter
and get their player from there.
local stats = thisplr.playerdata local score = stats.Tagged -- local plrname = script.Parent.Parent.Name -- ...don't do this. score.Value = thisplr.Name
local stats = thisplr:findFirstChild("playerdata")
is not how you do this because your way of doing it would error simply because you didn't use GetPlayerFromCharacter
. What you SHOULD do is local stats = thisplr:WaitForChild("playerdata")
. Also it's First
, not first
.
game.Players[thisplr].playerdata.Tagged.Value = plrname -- why did you use []? Just use thisplr.playerdata.Tagged.Value = plrname -- (using the remade locals) -- if it says it's not a string value still, just do -- score.Value = tostring(thisplr.Name), and it SHOULD work then.
Try these solutions, they might help. If you need me to explain, please ask!