bIorbee
(bIorbee)
May 20, 2021, 11:04pm
#1
im trying to make a name tag that would change on what button you press but instead of changing one person’s name tag it changes everyone’s name tag
code:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local first = game.ReplicatedStorage.NameTag:Clone()
first.Parent = char['Top Hat']
first.Adornee = char['Top Hat']
game.ReplicatedStorage.jobRep.nameTagCiv.OnServerEvent:Connect(function(id)
first.UpperText.Text = "∙ CIVILIAN ∙"
if plr.UserId == 46814587 or plr.UserId == 74770318 or plr.UserId == 50221335 then
first.LowerText.Visible = true
end
end)
game.ReplicatedStorage.jobRep.nameTagPolice.OnServerEvent:Connect(function()
first.UpperText.Text = "∙ POLICE ∙"
if plr.UserId == 46814587 or plr.UserId == 74770318 or plr.UserId == 50221335 then
first.LowerText.Visible = true
end
end)
game.ReplicatedStorage.jobRep.nameTagBank.OnServerEvent:Connect(function()
first.UpperText.Text = "∙ BANK EMPLOYEE ∙"
if plr.UserId == 46814587 or plr.UserId == 74770318 or plr.UserId == 50221335 then
first.LowerText.Visible = true
end
end)
game.ReplicatedStorage.jobRep.nameTagCab.OnServerEvent:Connect(function()
first.UpperText.Text = "∙ CAB DRIVER ∙"
if plr.UserId == 46814587 or plr.UserId == 74770318 or plr.UserId == 50221335 then
first.LowerText.Visible = true
end
end)
game.ReplicatedStorage.jobRep.cabQuit.OnServerEvent:Connect(function()
first.UpperText.Text = "∙ CIVILIAN ∙"
end)
game.ReplicatedStorage.jobRep.policeQuit.OnServerEvent:Connect(function()
first.UpperText.Text = "∙ CIVILIAN ∙"
end)
end)
end)
its a custom character btw
1 Like
Mikzul
(mikzul)
May 20, 2021, 11:15pm
#2
You can remove the whole playeradded characteradded part. You can get the player from the OnServerEvent.
for example, if i fire a remoteevent like this in a local script:
game.ReplicatedStorage.nameTagBank:FireServer()
The server script will get the player as the first argument. In the server script:
game.ReplicatedStorage.nameTagBank.OnServerEvent:Connect(function(player)
--and using that we can get the character
local chr = player.Character or player.CharacterAdded:Wait()
end)
I’m guessing since you’re setting up new connections for each player’s character, every single character is getting the same information, or something like that.
This could also lead to lag with the amount of unnecessary connections.
On an kinda unrelated note, to make a better whitelist you can use a table.
local whitelist = {
46814587,
74770318,
50221335,
}
if table.find(whitelist,player.UserId) then
print('This player is whitelisted.')
end
bIorbee
(bIorbee)
May 20, 2021, 11:36pm
#3
i also have another issue with something else dealing with leader board stats
so i have 3 ways you can get money and one way you lose money
the adding of the money and everything works normal but it doesnt add it to the right player here is my code that giving me the issue
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function()
if cash.Value >= 100 then
cash.Value -= 100
amnount = 100
elseif cash.Value < 100 then
cash.Value -= cash.Value
game.ReplicatedStorage.money.tag.text.Text = cash.Value
amnount = cash.Value
end
wait(5)
local clone = game.ReplicatedStorage.money:Clone()
clone.Parent = game.Workspace
clone.Position = Vector3.new(char.HumanoidRootPart.CFrame.X, char.HumanoidRootPart.CFrame.Y, char.HumanoidRootPart.CFrame.Z)
end)
end)
local stat = Instance.new("Folder")
stat.Name = "leaderstats"
stat.Parent = plr
local dss = game:GetService("DataStoreService")
local moneyStore = dss:GetDataStore("CornMoneyStore")
money = Instance.new("IntValue")
money.Name = "Corn coins"
money.Parent = stat
money.Value = moneyStore:GetAsync(plr.UserId.."-cash") or 0
wait(8)
stas = plr.leaderstats
cash = stas and stas:FindFirstChild("Corn coins")
end)