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

How to change leaderboard stats when a brick is getting touched?

Asked by 5 years ago

I need to change points when a brick is getting touched, and then it gets deleted on the client The only problem is with changing the leaderboard. I'm new to scripting so I might do some stupid mistakes

script.Parent.Touched:Connect(function(player1)
    if player1.Parent:FindFirstChild("Humanoid") then
    hit = game.Players:GetPlayerFromCharacter(player1.Parent)
    E = "game.Players." .. hit.Name .. ".leaderstats.Hidden.O" -- O = if the brick was touched
    E.Value=1 -- Change value of O
    game.ReplicatedStorage.touch:FireClient(hit)
    wait(1)
    end
end)
-- hidden is a folder and O is an IntValue

-- I need to somehow use E to change the value of O

When I touch the brick I get Workspace.Partttttt.Script:7: attempt to index global 'E' (a string value)

3 answers

Log in to vote
0
Answered by
CPF2 406 Moderation Voter
5 years ago

change line 4 from

E = "game.Players." .. hit.Name .. ".leaderstats.Hidden.O"

to

E = game.Players[hit.Name].leaderstats.Hidden.O
0
That was fast, thanks! User#23477 0 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Hi Shark,

It is right, you are using a String Value. E is set to a string value that you concatenated. You can just get the value by doing :WaitForChild() to each string.

So, something like this would most likely work:

local players = game:GetService("Players");

script.Parent.Touched:Connect(function(obj)
    local hum = obj.Parent:FindFirstChildOfClass("Humanoid");
    if hum then

            local char = obj.Parent;
        local player = players:GetPlayerFromCharacter(player1.Parent)

        E = player:WaitForChild("leaderstats"):WaitForChild("Hidden"):WaitForChild("O");
        E.Value = 1 -- Change value of O

            game.ReplicatedStorage.touch:FireClient(hit) -- I don't know anything about this one.
    end
end)

Hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

Log in to vote
0
Answered by 5 years ago

What I think you should do:

local partt = workspace.Partttttt
partt.Touched:connect(function(hit)
    local hum = hit.Parent:FindFirstChild('Humanoid')
    if hum then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        plr.leaderstats.Hidden.O.Value = plr.leaderstats.Hidden.O.Value + 1
    end
end)

When wanting to delete it you need to make it a local part and then use PartName:Destroy()

Just search up 'How to make local parts' and go onto the Roblox wiki to get your answer on creating local parts :)

Hope this helped!

Answer this question