Hi, i would like a script for my game... I want to pickup apples and put them in an not existing backpack ( a screen gui that says for an expample: 1/20 ), i would like that number to change whenever i click on an apple (add 1). Is that possible? Thanks if you can :D (btw the apples are called click)
COMMUNITY QUESTION
Can you make me a script to pickup apples into a screen gui?
2 answers
examples of updating text for inv
--[[
make a value in the player for apples (leaderstats also work if you have that, otherwise make a value)
local script inside the text label
]]
local player = game.Players.LocalPlayer
local value = player.amountofapples -- current amount of apples
local value2 = player.maxapples -- max amount of apples
-- one way (updates when apples change)
value:GetPropertyChangedSignal'Value':Connect(function() -- runs when amount changes
script.Parent.Text = tostring(value) .. '/' .. tostring(value2)
end)
-- different way (doesn't check when it changes, updates rly fast)
game:GetService'RunService'.RenderStepped:Connect(function() -- runs every second the player is in game
script.Parent.Text = tostring(value) .. '/' .. tostring(value2)
end)
example of picking up the apple
--[[
this would be a server script inside of the apple
]]
function pickUp(player)
if player.amountofapples and player.amountofapples < player.maxapples and player.maxapples <= player.amountofapples + 1 then -- checks to see if apples go over limit
player.amountofapples += 1
end
script.Parent:Destroy() -- deletes apple so they cant get again
end
-- if using proximity prompt you could do something like this
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
pickUp(player)
end
1 comment
0
I've been trying different thing, and it doesn't seem to be working. the script to "pick up" the apples, do i put it in the apple object?
For a simplified explanation, you would just use values, like shown:
-- Make sure you have a click detector inside of your apple and put a script inside of the apple
--Click detector script
local Debris = game:GetService("Debris")
local prompt = script.Parent
local apple = script.Parent.Parent
prompt.MouseClick:Connect(function(plr)
local remote = game:GetService("ReplicatedStorage").Remotes.Apple -- locate the remote event
remote:FireClient(plr)
Debris:AddItem(apple, 0.01)
end)
-- local script
-- Put this is starterGui
local maxStorage = 20
local apple = 0
local remoteEvent = game:GetService("ReplicatedStorage").Remotes.Apple -- again, locate the remote event you want to fire
remoteEvent.OnClientEvent:Connect(function()
apple += 1
local gui = nil -- Locate the gui you want to show
while wait() do
gui.Text = apple.."/"..maxStorage
end
end)
Tell me if you get any errors
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
This is not a request site.