I made a leaderboard script and a script so when I touch a brick it gives the player money.
Leaderboard:
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new('Model', player) leaderstats.Name = 'leaderstats' local Experience = Instance.new("IntValue", leaderstats) Experience.Name = "Experience" Experience.Value = 1 local Credits = Instance.new("IntValue", leaderstats) Credits.Name = "Credits" Credits.Value = 10 local vts = {Credits.Value, Experience.Value} local key = 'Player//'..player.userId local savedpoints = ds:GetAsync(key) if savedpoints then --Save Format: {'level', 'xp'} Experience.Value = savedpoints[1] Credits.Value = savedpoints[2] else ds:SetAsync(key, vts) end
end)
game.Players.PlayerRemoving:connect(function(player) local key = 'Player//'..player.userId local vts = {player.leaderstats.Experience.Value, player.leaderstats.Credits.Value} ds:SetAsync(key,vts) end)
This works fine, but now the problem is the script so when I touch a brick it gives money. Script:
local Model = script.Parent.Parent; local Part = Model:WaitForChild("Part"); local Players = game:FindService("Players");
local Ready = true;
function OnTouched(Hit) if not Ready then return nil; end; local Char = Hit.Parent; local Player = Players:GetPlayerFromCharacter(Char); if Player then Ready = false; Part.Transparency = 1; Player.leaderstats.Credits.Value = (Player.leaderstats.Credits.Value + 5); wait(300); Ready = true; end; end;
Part.Touched:Connect(OnTouched);
I added the leaderboard because I thought both were connected, and the problem could be either on the leaderboard or on the script. Another thing, when someone touches the brick's transparency changes to 1 how do I make it so it makes canCollide true? I've tried Ready = false; CanCollide = true; Part.Transparency = 1;
but doesn't work.
Thank you.