I've been trying to change the value of a stat "level" when a brick is touched. I have a LocalScript in the brick with this code:
function OnTouched(Part)
local level
print("Touched")
level.Value = level.Value + 1
end
script.Parent.Touched:Connect(OnTouched)
And this is the code for the leaderboard:
local function onPlayerJoin(player)
print("Joined")
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local jumps = Instance.new("IntValue")
jumps.Name = "Jumps"
jumps.Value = 0
jumps.Parent = leaderstats
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 0
level.Parent = leaderstats
local DebounceTime = .5
local CanJump = true
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
if humanoid.Jump == true and CanJump then
jumps.Value = jumps.Value + 1
CanJump = false
wait(DebounceTime)
CanJump = true
end
end)
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = Instance.new("RemoteEvent")
Remote.Parent = ReplicatedStorage
Remote.OnServerEvent:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
for _,v in pairs(leaderstats:GetChildren()) do
v.Value = 0
end
end
end)
Now -- Why doesn't the LocalScript in the brick work at all? I assumed that it was a problem with just level.Value = level.Value + 1. But when I put the print ("Touched") into the script, it never displayed it into the console.

1 comment
LocalScripts don't run in the Workspace; doing a little research would've answered this. https://developer.roblox.com/api-reference/class/LocalScript