[SOLVED] How I Would Add An Back Accessory To A Player's Back If a String Value Doesn't Contain Any String?

So I Been Trying to add a back accessory if a string value doesn’t have any string text
But Every Time It Won’t Add An accessory to the character’s back, it won’t throw anything in output,etc.

i searched on Developer Forum or Developer Hub,But Still Nothing In Output, Won’t put The back accessory

Can Someone Help Me?

(Sorry if im bad at explaining)

2 Likes

It could be that the string value’s value is an empty string instead of nil. Have you tried comparing to ""?

1 Like

No Like I Made A String Value That’s Empty,so like if the string value is “” the Client Would Detect that the player is new and would give him the starter wings. This What I Have So Far:

local playerModel = script.Parent
local humanoid = playerModel:WaitForChild(“Humanoid”)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if player.Stats.CurrentWings.Value ~= “” or player.Stats.CurrentWings.Value ~= " " then
local wingsstarter = Instance.new(“Accessory”)
wingsstarter.Name = “StarterWings”
local handle = Instance.new(“Part”)
handle.Name = “Handle”
handle.Parent = wingsstarter
local specialmesh = Instance.new(“SpecialMesh”)
specialmesh.Name = “SpecialMesh”
specialmesh.MeshId = “rbxassetid://2963816633”
specialmesh.TextureId = “rbxassetid://2963804498”
specialmesh.Parent = handle
local BodyThrust = game.ReplicatedStorage.BodyThurst.BodyThrust1:Clone()
BodyThrust.Parent = handle
local BodyBackAttachment = Instance.new(“Attachment”)
BodyBackAttachment.Name = “BodyBackAttachment”
BodyBackAttachment.Parent = handle
wingsstarter.Parent = character
end
end)
end)

Try instead of parenting the back accessory to the character, you use the character’s humanoid and call Humanoid:AddAccessory. Can you add a print statement where the accessory is parented to make sure it’s making it to that line first?

Other stuff I caught
  1. Using game.Players.PlayerAdded seems excessive for a script that already has the character, I’m assuming playerModel. You can find the player from the character using the Players:GetPlayerFromCharacter method, and access stats from there.

  2. Maybe you’re not waiting long enough for the data to load? Probably not though, since the back accessory just isn’t being loaded, no errors thrown.

  3. You can put your code in a code block by using three backticks ``` at the beginning of your code and three more at the end. They can be found to the left of the 1 key.

Input:
```
local x = 8
-- code here
```

Output:

local x = 8
-- code here

Ok I Will Try These Methods 30characterlimits

1 Like

ok so i did all what u sayed but still nothing, i waited like 2 minutes, i used Humanoid:AddAccessory(), used Print() and also remade the local script.

–localscript:

local playerModel = script.Parent
local player = game.Players.LocalPlayer
local Humanoid = playerModel:WaitForChild("Humanoid",3)

if player.Stats.CurrentWings.Value ~= "" or player.Stats.CurrentWings.Value ~= " " then
	if game:IsLoaded() then do
           local wingsstarter = Instance.new("Accessory")
           wingsstarter.Name = "StarterWings"
           local handle = Instance.new("Part")
		   handle.Name = "Handle"
		   handle.Parent = wingsstarter
		   local specialmesh = Instance.new("SpecialMesh")
		   specialmesh.Name = "SpecialMesh"
		   specialmesh.MeshId = "rbxassetid://2963816633"
		   specialmesh.TextureId = "rbxassetid://2963804498"
		   specialmesh.Parent = handle
		   local BodyThrust = game.ReplicatedStorage.BodyThurst.BodyThrust1:Clone()
		   BodyThrust.Parent = handle
		   local BodyBackAttachment = Instance.new("Attachment")
		   BodyBackAttachment.Name = "BodyBackAttachment"
		   BodyBackAttachment.Parent = handle
		   local A,E = pcall(function()
			 Humanoid:AddAccessory(wingsstarter)
		     end)
		       if A then
			    warn("WINGS_DEBUG: Added Wings Successfuly.")
		    end
		     if E then
			    warn("WINGS_DEBUG: Error!")
		    end
        end
	end
end

1 Like

AddAccessory does not work properly when called from a LocalScript. You will need to fire a RemoteEvent here instead and catch the event with a server Script that calls AddAccessory.

Also, pcalling this does nothing.

1 Like

ok,i will try with a RE(Remote Event) and delete the pcall()

Actually, if you don’t need any information from the client and the client isn’t triggering this by doing something, you just should do all of this code in a server Script and skip the remote.

From The Client I Just Need To Check Only If The String Value is “” because the server-script can’t access the local player at all

Are you creating values throught the client? Be aware that if you are, and the client tells the server it’s data, that your game will be easily exploitable.

No Like The Client Will Check If The String value is “” and if the string value the client will fire a remoteEvent

Is there a reason you can’t just do this all on the server? It seems really inefficient to have to get the client to check, which will take time, and the server to wait for that response.

yeah. I Use StringValue Because Its Easier Like To know What Wings The Player Has And I Can Also Use DataStore (I Think) to save

Where is this string value located? You told me it was on the server, now it’s on the client? From where is that value created? Can you not access it from the server?

The Value Is In The Leaderstats And The Server Can’t Access the Player at all, and the value is Created In The Stats Script(In ServerScriptService)

@PeZsmistic Thanks! I Finally Made It.

I Also Wanna Say Thanks To Every One Who Helped And tried to help me!

1 Like