Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

my sword fighting game tagging system wont work?

Asked by 2 years ago

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)
0
Output? Xapelize 2658 — 2y

1 answer

Log in to vote
1
Answered by
Antelear 185
2 years ago
Edited 2 years ago

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!

0
P.S try to format your code, aka don't let it be a clutter. Antelear 185 — 2y
0
it's P.S. not P.S, syntax error >:v imKirda 4491 — 2y
0
even after i put tostring it keeps saying it expects a string not an instance Just_Pointless 0 — 2y
0
@Just_Pointless then make it stop expecting an INSTANCE (obviously XD) Antelear 185 — 2y
View all comments (2 more)
0
no i ment it wants a string but it keeps giving it an instance Just_Pointless 0 — 2y
0
i mean SPECIFY which line it errors at. Antelear 185 — 2y
Ad

Answer this question