Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Adding +1 "DRONKS" when drink bloxy cola. (?)

hello, I want to make a simulator game where you gain "DRONKS" whenever you drink the bloxy cola. the bloxy cola is a well known roblox item, if you dont know here is the script of bloxy cola.

local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled  then
		return
	end

	enabled = false
	Tool.GripForward = Vector3.new(0,-.759,-.651)
	Tool.GripPos = Vector3.new(1.5,-.5,.3)
	Tool.GripRight = Vector3.new(1,0,0)
	Tool.GripUp = Vector3.new(0,.651,-.759)


	Tool.Handle.DrinkSound:Play()

	wait(3)
	
	local h = Tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		if (h.MaxHealth > h.Health + 5) then
			h.Health = h.Health + 5
		else	
			h.Health = h.MaxHealth
		end
	end

	Tool.GripForward = Vector3.new(-.976,0,-0.217)
	Tool.GripPos = Vector3.new(0.03,0,0)
	Tool.GripRight = Vector3.new(.217,0,-.976)
	Tool.GripUp = Vector3.new(0,1,0)

	enabled = true

end

function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

sorry, i am new to coding on roblox.

1 answer

✓ Accepted answer

So this is the script you're putting into the tool?

Make a separate script and put it into ServerScriptService, and put the code below into it

local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("PutSomethingRandomHere")
local currencyName = 'Dronks'

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new('Folder')
leaderstats.Name = 'leaderstats'
leaderstats.Parent

local currency = Instance.new('NumberValue')
currency.Name = currencyName
currnecy.Value = 0 or ds:GetAsync(player.UserId)
currency.Parent = leaderstats

game.Players.PlayerRemoving:Connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats:FindFirstChild(currencyName).Value)

3 comments

0

I forgot to say, then you have to get the player instance somewhere in your tool script, and on the "activtaed" part, you'll need to do player.leaderstats.Dronks.Value = player.leaderstats.Dronks.Value + 1

0

thanks!

0

no problemo!

This discussion is preserved as it was. New answers, comments, and votes are closed.