Hello everyone!
This topic is continuous from the following:
Can I call a module script from a local script in StarterPlayerScripts folder?
I move the module script to ReplicatedStorage and now no errors are shown.
After modifying some, now the local script in StarterPlayerScript folder is as follows:
local remote = game:GetService(“ReplicatedStorage”).Remotes.GiveCurrency
local QA_Manager = require(game.ReplicatedStorage.QA_Manager)–Module script to set up questions and answers sets
local question, answers = QA_Manager.parseCsv()
local coinSound = game.SoundService.CoinSound–Sound when a game currency is picked up
local smallHeart = game.Workspace.SmallHeart – Visual effect when a game currency is picked up
–local sh = smallHeart:Clone()
local credit = game.Workspace.Credit --Display of “+1” when a game currency is picked up
–local cr = credit:Clone()
local players = game:GetService(“Players”)
local player = players.LocalPlayer
local chr = player.Character or player.CharacterAdded:wait()
local humanoid = chr:WaitForChild(“Humanoid”)
local root = chr:FindFirstChild(“HumanoidRootPart”)
local amount = 1 – Unit amount of the game currency
local debounce = false
local qa = game.Workspace.QA – QA Folder accommodating all questions and answers sets
for _, stage in pairs (qa:GetChildren()) do – Multiple stages
for _, eachQA in pairs(stage:GetChildren()) do --Each stage has 5 QA sets.
if eachQA.A1_Board.SurfaceGui.TextLabel.Text == QA_Manager.correctAnswer then – Each QA set has 1 question board and 4 answer boards
eachQA.A1_Board.OnTouched:Connect(function(hit)
if hit.Parent:WaitForChild(humanoid) and debounce == false then
debounce = true
remote:FireServer(amount) --Update the player’s game currency amount on server.
coinSound:Play() – Sound effect when the player touche the correct board
local sh = smallHeart:Clone() – Shows small heart above the player’s head when the player touches the correct board
local cr = credit:Clone() – Shows “+1” under the small heart.
sh.Position = root.Position + Vector3.new(0, 4, 0)
cr.Position = root.Position + Vector3.new(0,2,0)
wait(1)
sh:Destory()
cr:Destory()
debounce = false
end
end)
elseif eachQA.A2_Board.SurfaceGui.TextLabel.Text == QA_Manager.correctAnswer then -- Each QA set has 1 question board and 4 answer boards
eachQA.A2_Board.OnTouched:Connect(function(hit)
if hit.Parent:WaitForChild(humanoid) and debounce == false then
debounce = true
remote:FireServer(amount) --Update the player's game currency amount on server.
coinSound:Play() -- Sound effect when the player touche the correct board
local sh = smallHeart:Clone() -- Shows small heart above the player's head when the player touches the correct board
local cr = credit:Clone() -- Shows "+1" under the small heart.
sh.Position = root.Position + Vector3.new(0, 4, 0)
cr.Position = root.Position + Vector3.new(0,2,0)
wait(1)
sh:Destory()
cr:Destory()
debounce = false
end
end)
elseif eachQA.A3_Board.SurfaceGui.TextLabel.Text == QA_Manager.correctAnswer then -- Each QA set has 1 question board and 4 answer boards
eachQA.A3_Board.OnTouched:Connect(function(hit)
if hit.Parent:WaitForChild(humanoid) and debounce == false then
debounce = true
remote:FireServer(amount) --Update the player's game currency amount on server.
coinSound:Play() -- Sound effect when the player touche the correct board
local sh = smallHeart:Clone() -- Shows small heart above the player's head when the player touches the correct board
local cr = credit:Clone() -- Shows "+1" under the small heart.
sh.Position = root.Position + Vector3.new(0, 4, 0)
cr.Position = root.Position + Vector3.new(0,2,0)
wait(1)
sh:Destory()
cr:Destory()
debounce = false
end
end)
elseif eachQA.A4_Board.SurfaceGui.TextLabel.Text == QA_Manager.correctAnswer then -- Each QA set has 1 question board and 4 answer boards
eachQA.A4_Board.OnTouched:Connect(function(hit)
if hit.Parent:WaitForChild(humanoid) and debounce == false then
debounce = true
remote:FireServer(amount) --Update the player's game currency amount on server.
coinSound:Play() -- Sound effect when the player touche the correct board
local sh = smallHeart:Clone() -- Shows small heart above the player's head when the player touches the correct board
local cr = credit:Clone() -- Shows "+1" under the small heart.
sh.Position = root.Position + Vector3.new(0, 4, 0)
cr.Position = root.Position + Vector3.new(0,2,0)
wait(1)
sh:Destory()
cr:Destory()
debounce = false
end
end)
end
end
end
This script returns no errors, but when I test play, nothing is shown when I touch the correct board.
I appreciate if someone point out any mistakes!