Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

my sword fighting game tagging system wont work?

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)

1 comment

0

Output?

1 answer

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!

6 comments

0

P.S try to format your code, aka don't let it be a clutter.

0

it's P.S. not P.S, syntax error >:v

0

even after i put tostring it keeps saying it expects a string not an instance

0

@Just_Pointless then make it stop expecting an INSTANCE (obviously XD)

0

no i ment it wants a string but it keeps giving it an instance

0

i mean SPECIFY which line it errors at.

This discussion is preserved as it was. New answers, comments, and votes are closed.