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

Wont refresh when the player resets?

Asked by 6 years ago
Edited 6 years ago
local Hat = game.ReplicatedStorage:WaitForChild("Hat_1")
local Player = game.Players.LocalPlayer
local Char = Player.Character
local Humanoid = Char:WaitForChild("Humanoid")

function GetPlayers()
for _,v in pairs(game.Players:GetChildren()) do
    if v.Name == "Player1" then
         Humanoid:AddAccessory(Hat)
           end 
       end
   -- print ("No errors found.")
end

GetPlayers()

This is a LocalScript. I'm almost certain it has something to do with an if statement. I also know that functions repeat but apparently not this one.

UPDATE

local Hat = game.ReplicatedStorage:WaitForChild("Hat_1")
local Player = game.Players.LocalPlayer
local Char = Player.Character
local Humanoid = Char:WaitForChild("Humanoid")

if Player.Name == "Player1" then
        Humanoid:AddAccessory(Hat)
    print ("Fluid.")
end

So apparently you can't reset the function AddAccessory(). I've tried cloning with the Add() function and it did not work. I have been told that I can "repeat" this by adding the accessory every time they respawn however I don't know how to go about this. Any help?

1
Why would you want to do this with all the players? Why just the specific player? TheeDeathCaster 2368 — 6y

1 answer

Log in to vote
8
Answered by 6 years ago
Edited 3 years ago

This gives the hat to you so you can wear it, works perfectly fine.

------- VARIABLES -------

local players = game:GetService("Players");
local priveliged_players = {"Player1", "KingLoneCat", "Somebody", "greatneil80"}
local rs = game:GetService("ReplicatedStorage");
------- VARIABLES -------

------- FUNCTIONS -------
players.PlayerAdded:Connect(function(plr)  
    for _,v in next, priveliged_players do
      if plr.Name == v then
            plr.CharacterAdded:Connect(function(char)
            local hats = rs:WaitForChild("Hats"):GetChildren();
            for _,v in next, hats do
              local hat = v:Clone();
              hat.Parent = char;
          end
            end)
        end
    end
end)

0
upvote the question 2 bb :) AdvancedCode 136 — 6y
0
coooooooooooool raid6n 2196 — 3y
0
yeaaaaaaaaaaaaaaaaa greatneil80 2647 — 3y
Ad

Answer this question