How To Combine This Scripts

How To Combine This Scripts

local TweenService = game:GetService("TweenService")
local Folder = game.Workspace.Map.Orbs --Location of Orb

local function bindDummy(EachOrb) --Start function
	coroutine.resume(coroutine.create(function()
		while task.wait() do
			EachOrb.CFrame = EachOrb.CFrame * CFrame.Angles(0, 0.05, 0)
		end
	end))
	
	local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, math.huge, true)
	local tween = TweenService:Create(EachOrb, info, {Position = EachOrb.Position + Vector3.new(0, 1.5, 0)})
	tween:Play()
end --End function

for _, EachOrb in pairs(Folder:GetChildren()) do -- Bind all existing dummies
	bindDummy(EachOrb)
end --End for
Folder.ChildAdded:Connect(bindDummy) -- Bind all future dummies

and

WaitTime = 10 -- How many seconds to respawn the coin!
Amount = 1 -- Amount of coins per coin!
function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:FindFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local Score = stats:findFirstChild("Coins")
				if (Score~=nil) then
					Score.Value = Score.Value + Amount
				end
			end
		end
		script.Parent.ParticleEmitter.Enabled = false
		script.Parent.PointLight.Enabled = false	
		script.Parent.Transparency = 1
		script.Disabled = true
		task.wait(WaitTime)
		script.Parent.Transparency = 0
		script.Disabled = false
		script.Parent.ParticleEmitter.Enabled = true
		script.Parent.PointLight.Enabled = true	
	end
end

script.Parent.Touched:Connect(onTouched)

Note: It is not recommended to bundle all your functions in a single script.

local TweenService = game:GetService("TweenService")
local Folder = game.Workspace.Map.Orbs --Location of Orb

local Amount = 1 -- Amount per coin
local WaitTime = 10 -- How many seconds to respawn the coin!

local function bindDummy(EachOrb) --Start function
	coroutine.resume(coroutine.create(function()
		while task.wait() do
			EachOrb.CFrame = EachOrb.CFrame * CFrame.Angles(0, 0.05, 0)
		end
	end))
	
	EachOrb.Touched:Connect(function(part) -- Create orb touch event
		if part.Parent:FindFirstChild("Humanoid") then
			local thisplr = game.Players:GetPlayerFromCharacter(part.Parent)
			local _stats = thisplr:FindFirstChild("leaderstats")
			
			if _stats ~= nil then
				local Coins = _stats:FindFirstChild("Coins")
				if Coins ~= nil and EachOrb.Transparency == 0 then
					
					EachOrb.ParticleEmitter.Enabled = false
					EachOrb.PointLight.Enabled = false	
					EachOrb.Transparency = 1
					
					Coins.Value = Coins.Value + Amount
					task.wait(WaitTime)
					
					EachOrb.Transparency = 0
					EachOrb.ParticleEmitter.Enabled = true
					EachOrb.PointLight.Enabled = true
				end
			end
		end
	end)
	
	local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, math.huge, true)
	local tween = TweenService:Create(EachOrb, info, {Position = EachOrb.Position + Vector3.new(0, 1.5, 0)})
	tween:Play()
end --End function

for _, EachOrb in pairs(Folder:GetChildren()) do -- Bind all existing dummies
	bindDummy(EachOrb)
end --End for
Folder.ChildAdded:Connect(bindDummy) -- Bind all future dummies

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.