Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

change line 4 from

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

to

E = game.Players[hit.Name].leaderstats.Hidden.O

1 comment

0

That was fast, thanks!

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

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.