Hello developers! Me and a friend are trying to create a tycoon to learn more about scripting and game creation and have come upon an issue in our script.
We have a money collector area, in which you can collect your cash. So while testing in studio, by ourselves, it works fine. Every time a dropper’s part goes through the conveyor, it adds cash to the area to collect, and the player can then stand on it to collect. However while using the “team test” feature. The number remains at 0, and the money is non-collectible and I believe isn’t even registered. We do not know why this occurs. Anything will help.
moneycollect script (for collecting money) :
debounce = false
script.Parent.Touched:Connect(function(hit)
wait()
local Character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if debounce == false and Humanoid ~= nil and player.Team == game.Teams["Purple Tycoon"] then
debounce = true
print("hit")
local money = game.ServerStorage.moneytogive.Value
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
print(player)
print(player)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + money
print("hit it")
game.ServerStorage.moneytogive.Value = 0
wait(4)
debounce = false
end
end)
Script that shows money amount:
wait(0.1)
text = script.Parent
money = game.ServerStorage.moneytogive
while true do
text.Text = money.Value
end
Could you possibly clean up your script/explain what things are supposed to do? Using a variable name like moneytogive is extremely vague and confusing.
Please keep variables that need to be referenced once out of inner scopes… You are also duplicating some code… You have a variable named player twice. When it was already declared from an outer scope inside your anonymous function block of code.
local ServerStorage = game:GetService("ServerStorage")
local moneyToGive = ServerStorage:FindFirstChild("moneytogive")
script.Parent.Touched:Connect(function(hit)
wait()
local Character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if debounce == false and Humanoid ~= nil and player.Team == game.Teams["Purple Tycoon"] then
debounce = true
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + moneyToGive.Value
moneyToGive.Value = 0
wait(4)
debounce = false
end
end)
For updating your TextLabel you should be utilizing the instance:GetPropertyChangedSignal("property") method like @Conejin_Alt mentioned.