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
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
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.
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.
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.
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
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.
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.
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.
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.
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?