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 7 years ago
Edited 7 years ago
01local Hat = game.ReplicatedStorage:WaitForChild("Hat_1")
02local Player = game.Players.LocalPlayer
03local Char = Player.Character
04local Humanoid = Char:WaitForChild("Humanoid")
05 
06function GetPlayers()
07for _,v in pairs(game.Players:GetChildren()) do
08    if v.Name == "Player1" then
09         Humanoid:AddAccessory(Hat)
10           end
11       end
12   -- print ("No errors found.")
13end
14 
15GetPlayers()

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

1local Hat = game.ReplicatedStorage:WaitForChild("Hat_1")
2local Player = game.Players.LocalPlayer
3local Char = Player.Character
4local Humanoid = Char:WaitForChild("Humanoid")
5 
6if Player.Name == "Player1" then
7        Humanoid:AddAccessory(Hat)
8    print ("Fluid.")
9end

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 — 7y

1 answer

Log in to vote
8
Answered by 7 years ago
Edited 4 years ago

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

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

01local players = game:GetService("Players");
02local priveliged_players = {"Player1", "KingLoneCat", "Somebody", "greatneil80"}
03local rs = game:GetService("ReplicatedStorage");
04------- VARIABLES -------
05 
06------- FUNCTIONS -------
07players.PlayerAdded:Connect(function(plr) 
08    for _,v in next, priveliged_players do
09      if plr.Name == v then
10            plr.CharacterAdded:Connect(function(char)
11            local hats = rs:WaitForChild("Hats"):GetChildren();
12            for _,v in next, hats do
13              local hat = v:Clone();
14              hat.Parent = char;
15          end
16            end)
17        end
18    end
19end)
0
upvote the question 2 bb :) AdvancedCode 136 — 7y
0
coooooooooooool raid6n 2196 — 4y
0
yeaaaaaaaaaaaaaaaaa greatneil80 2647 — 4y
Ad

Answer this question