Hey there, New scripter here,
I'm trying to create a Quest like system were there is a GUI at the top of the screen saying "Books Found 0/4"
Now im trying to create it were when you touch a Part(Book) the number would change to 1/4 ect ect...
Not sure were to really start but i understand string.gsub seems right?
Thanks,
Here are the steps: 1. First, add a RemoteEvent into ReplicatedStorage and name it to bookCollected 2. Second, add a LocalScript into the text you are displaying this in 3. Third, add a ServerScript into the books
Here's the code:
ServerScript inside the book Object
script.Parent.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then local player = game.Players:GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.bookCollected:FireClient(player) end end)
LocalScript:
local text = script.Parent local booksFound = 0 -- by default unless you save it, I'll let you deal with that since it isn't related to the question game.ReplicatedStorage.bookCollected.OnClientEvent:Connect(function() booksFound = booksFound + 1 if booksFound < 4 then text.Text = 'Books Found ' .. booksFound .. '/4' else text.Text = 'Books Found 4/4' -- Add additional code to do when quest is complete end end)
That should do the job!
Like I stated before, if your text label is a fixed “0/4 Quests” then you should use ‘string.gsub’ There are patterns and the one your looking for is ‘%d’ which finds the first number in a text/string.
Here’s an example:
local textlabel = script.Parent — this label will have an example text like “0/5 Found” if player_found_quest then local number = tonumber(textlabel.Text:match(‘%d’)) — this will give you ‘0’ since it is the first digit of that text textlabel.Text = string.gsub(textlabel.Text, ‘%d’, tostring(number+1)) end — this will add 1 to the text for example: “1/5 Found”