So I only picked up scripting a couple days ago and I've been experimenting with a lot of different things. I've spent a good amount of time making a crate spawn system and trying to figure out how to make it so that if a player touches the crate, they would get 10 cash. However, every attempt I've made seems to fail. Below you can see what I've ended up with. The top portion is the crate spawning script and the bottom is the reward script.
while true do
local crate = game.Workspace.Crate:Clone()
crate.Parent = workspace
crate.Name = "MoneyCrate"
crate.Transparency = 0
crate.CanCollide = true
crate.Anchored = false
local X = math.random(-256,256)
local Y = 100
local Z = math.random(-256,256)
crate.Position = Vector3.new(X,Y,Z)
wait(60)
end
local function receiveMoney(part)
if part.Parent:FindFirstChild("Humanoid") ~= nil then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
player.leaderstats.Money.Value = player.leaderstats.Money.Value + 10
game.Workspace.MoneyCrate:Destroy()
end
end
game.Workspace.MoneyCrate.Touched:connect(receiveMoney)

1 comment
Thanks a lot for the advice, solved my problem and will be useful to know in the future.