hello, i have a script to show before i need any help, firstly is this piece of code in serverscriptservice.
AttackModeActivated.Event:Connect(function(character)
local player = Players:GetPlayerFromCharacter(character)
allPlayers[table.find(allPlayers, player)].AttackModeActivations.Value += 1
AMLChanged:FireAllClients(allPlayers)
end)
A bindable event fires once the player touches the brick and its meant to update a custom leaderstats GUI but it doesnt as this piece of code doesnt work when the player touches the part. I know it doesnt add the value as I checked and it stays at 0, any help?
the script inside a part to fire the bindable event
local Stage2 = script.Parent
local AttackModeActivated = game.ServerStorage.AttackModeActivated
Stage2.Touched:Connect(function(otherPart)
local model = otherPart:FindFirstAncestorOfClass("Model")
if(model and model:FindFirstChildWhichIsA("Humanoid")) then
AttackModeActivated:Fire(model)
end
end)
as well as this one which is inside of the custom leaderstats gui:
which updates every time the leaderstats changed event is fired
local StatsFrame = script.Parent.Stats
local PlayerScores = StatsFrame.PlayerStats
local LeaderboardPlayerTemplate = game.ReplicatedStorage.PlayerScore
local AMLChanged = game.ReplicatedStorage.Events.AMLChanged
local playerScoresFrame = {}
local function UpdateStatsUI(_players)
if (#playerScoresFrame < #_players) then
for i = #playerScoresFrame + 1, #_players, 1 do
local StatsTemplate = LeaderboardPlayerTemplate:Clone()
StatsTemplate.Parent = PlayerScores
playerScoresFrame[i] = StatsTemplate
end
end
if (#playerScoresFrame > #_players) then
for i = #_players + 1, #playerScoresFrame, 1 do
playerScoresFrame[i]:Destroy()
playerScoresFrame[i] = nil
end
end
for i,v in ipairs(_players) do
playerScoresFrame[i].PlayerName.Text = _players[i].Username.Value
playerScoresFrame[i].PlayerScore.Text = _players[i].AttackModeActivations.Value
playerScoresFrame[i].PlayerPhoto.Image = _players[i].Thumbnail.Value
end
end
AMLChanged.OnClientEvent:Connect(UpdateStatsUI)
I knew it! Try to replace the code with my code in my previous response so the function will look like this:
AttackModeActivated.Event:Connect(function(character)
local player = Players:GetPlayerFromCharacter(character)
player.AttackModeActivations.Value += 1
AMLChanged:FireAllClients(allPlayers)
end)
Thats wierd. Can you launch the game and send me everything under the player. Basically what i think is happening is that the value AttackModeActivation doesnt exist in the player. It is wierd that its referencing line 38 wich fires a event.