(sorry for low english)

i tried this code:

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local trail = game.ServerStorage.Trail:Clone()
trail.Parent = char.Head
local attachment0 = Instance.new("Attachment",char.Head)
attachment0.Name = "TrailAttachment0"
local attachment1 = Instance.new("Attachment",char.HumanoidRootPart)
attachment1.Name = "TrailAttachment1"
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
end)
end)

yes, it works but it only works on player join. i need MouseButton1Click and leaderstat cash value (>= 10)

and i made this code and it didnt work:


local DataStore = game:GetService("DataStoreService")
local Datastore1 = DataStore:GetDataStore("test")

script.Parent.MouseButton1Click:Connect(function(player)

	local money = player.leaderstats.Cash.Value
	
	if money >= 10 then
		Ds1:SetAsync(player.UserId,  player.leaderstats.Money.Value - 10)
		player.leaderstats.Money.Value = Ds1:GetAsync(player.UserId) or 0
		print(player.leaderstats.Money.Value)
	end
end)

this is output: Players.Selim_Emin.PlayerGui.shp.shp1.shp2.shp3.trail.Script:6: attempt to index nil with 'leaderstats'

2 comments

1

The script is not finding the leaderstats. Try doing local money = player:FindFirstChild("leaderstats").Cash.Value

0

Use player:WaitForChild("leaderstats").Money.Value