Script not working on Roblox, but works fine in studio?

Hello,

I’ve been working on the script for a quest that takes place in my game. The script works fine in Roblox Studio, but doesn’t work in the Roblox Player.

STUDIO:
robloxapp-20210913-1103190.wmv (1.7 MB)
ROBLOX:
robloxapp-20210913-1104317.wmv (1.7 MB)

The main Script (there are more scripts, but this is the one I think is affected):

--//Services 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--//Variables
local player = Players.LocalPlayer
local screenGui = script.Parent.ScreenGui
local talkButton = script.Parent.Quest1TalkGui.Talk
local talkButtonBox = script.Parent.Quest1TalkGui.SquareImage
local questBox = screenGui.QuestBox
local speech = screenGui.Speech
local answer1 = screenGui.Answer1
local box1 = screenGui.Answer1Box
local box2 = screenGui.Answer2Box
local answer2 = screenGui.Answer2
local counterBox = screenGui.CounterBox
local questFolder = ReplicatedStorage:WaitForChild("Quest1")
local giveBalloon = questFolder.GiveBalloon 
local giveValues = questFolder.GiveValues
local quest1Values = player:WaitForChild("Quest1Values")
local completed = quest1Values.Completed
local dialogueTracker =  quest1Values.SpeechValue
local clickSound = ReplicatedStorage.SoundEffects:WaitForChild("ClickSound")
local typingSound = ReplicatedStorage.SoundEffects:WaitForChild("Typing")
--//Functions

local function answerSwitch()
	answer1.Visible = not answer1.Visible
	answer2.Visible = not answer2.Visible
	box1.Visible = not box1.Visible
	box2.Visible = not box2.Visible
end

local function speechAssigner(speechNumber)
	local mainSpeech = questFolder:WaitForChild("Speech"..tostring(speechNumber))
	local speechValue = mainSpeech.Value
	answer1.Text, answer2.Text = mainSpeech:WaitForChild("Answer1").Value, mainSpeech:WaitForChild("Answer2").Value
	typingSound:Play()
	for i = 1, #speechValue do
		speech.Text = string.sub(speechValue,1,i)
		wait(0.04)
	end
	typingSound:Pause()
	answerSwitch()
end

local function positiveAnswerFunction()
	giveValues:FireServer(dialogueTracker, dialogueTracker.Value + 1)
	answerSwitch()
	wait(0.1)
	speechAssigner(dialogueTracker.Value)
end

local function negativeAnswerFunction()
	answerSwitch()
	questBox.Visible = false 
	speech.Visible = false
	speech.Text = ""
	giveValues:FireServer(dialogueTracker, 0)
	wait(0.1)
	talkButton.Visible = true
	talkButtonBox.Visible = true
end
--//Script 

talkButton.MouseButton1Click:Connect(function()
	clickSound:Play()
	if dialogueTracker.Value ~= 0 and dialogueTracker.Value ~= 5 and dialogueTracker.Value == 6 and dialogueTracker.Value == 7 then
		dialogueTracker.Value = 0
		giveValues(dialogueTracker, dialogueTracker.Value + 1)
		questBox.Visible = true
		speech.Visible = true
		talkButton.Visible = false
		talkButtonBox.Visible = false
		speechAssigner(tostring(dialogueTracker.Value))
	elseif dialogueTracker.Value == 5 or dialogueTracker.Value == 6 or dialogueTracker.Value == 7 then
		questBox.Visible = true
		speech.Visible = true
		talkButton.Visible = false
		talkButtonBox.Visible = false
		speechAssigner(tostring(dialogueTracker.Value))
	else 
		giveValues:FireServer(dialogueTracker, dialogueTracker.Value + 1)
		questBox.Visible = true
		speech.Visible = true
		talkButton.Visible = false
		talkButtonBox.Visible = false
		wait(0.1)
		speechAssigner(tostring(dialogueTracker.Value))
	end
end)

answer1.MouseButton1Click:Connect(function()
	clickSound:Play()
	if dialogueTracker.Value == 1 then
		negativeAnswerFunction()	
	elseif dialogueTracker.Value == 2 then
		positiveAnswerFunction()
	elseif dialogueTracker.Value == 3 then
		positiveAnswerFunction()
	elseif dialogueTracker.Value == 4 then
		giveValues:FireServer(dialogueTracker, dialogueTracker.Value + 1)
		answerSwitch()
		counterBox.Visible = true
		questBox.Visible = false 
		speech.Visible = false
		talkButton.Visible = true
		talkButtonBox.Visible = true
		for i, v in pairs(game.Workspace:WaitForChild("Quest1Bags"):GetChildren()) do
			v.CanTouch = true
			v.Transparency = 0
		end
	elseif dialogueTracker.Value == 5 then
		answerSwitch()
		questBox.Visible = false 
		speech.Visible = false
		talkButton.Visible = true
		talkButtonBox.Visible = true
	elseif dialogueTracker.Value == 6 then 
		giveValues:FireServer(completed, true)
		answerSwitch()
		questBox.Visible = false 
		speech.Visible = false
		giveBalloon:FireServer()
		counterBox.Visible = false
		talkButton.Visible = true
		talkButtonBox.Visible = true
		giveValues:FireServer(dialogueTracker, dialogueTracker.Value + 1)
	elseif dialogueTracker.Value == 7 then
		questBox.Visible = false
		speech.Visible = false
		talkButton.Visible = true
		talkButtonBox.Visible = true
		answerSwitch()
	end
end)

answer2.MouseButton1Click:Connect(function()
	clickSound:Play()
	if dialogueTracker.Value == 1 then
		positiveAnswerFunction()
	elseif dialogueTracker.Value == 2 then
		positiveAnswerFunction()
	elseif dialogueTracker.Value == 3 then
		positiveAnswerFunction()
	elseif dialogueTracker.Value == 4 then
		negativeAnswerFunction()
	elseif dialogueTracker.Value == 5 then
		answerSwitch()
		questBox.Visible = false 
		speech.Visible = false
		talkButton.Visible = true
		talkButtonBox.Visible = true
	elseif dialogueTracker.Value == 6 then
		giveValues:FireServer(completed, true)
		answerSwitch()
		questBox.Visible = false 
		speech.Visible = false
		giveBalloon:FireServer()
		counterBox.Visible = false
		talkButton.Visible = true
		talkButtonBox.Visible = true
		giveValues:FireServer(dialogueTracker, dialogueTracker.Value + 1)
	elseif dialogueTracker.Value == 7 then
		questBox.Visible = false
		speech.Visible = false
		talkButton.Visible = true
		talkButtonBox.Visible = true
		answerSwitch()
	end
end)
2 Likes

Try commiting the script! Sometimes when you turn on a setting ROBLOX studio makes you need to commit it before it goes into ROBLOX itself. :slight_smile:

Hope this helped!

I do not have team create enabled. Should I enable it and then commit the scripts?

Turn on team create even if you don’t have anyone to work with because it saves you from crashing and loosing your progress because team create update saves every 5 minutes. Also you commit the scripts for it to go to roblox.

I just enabled team create, but the drafts tab isn’t appearing. How am I supposed to commit the scripts?
image

The reason why it’s not appearing is because you need to restart studio.

I did restart my studio, but nothing happened.

Also, if you look at the script you’ll see that only part of the script isn’t working. Not the full script.

Which section of your script isn’t working?

When the drafts button is not there, in order to commit a new version of a script, simply close the script using the “X” beside the script name at the top (under the toolbar). Then, you’ll see a message in the output saying that you’ve submitted a new version of the script.

The speech assigner function is the one that isn’t working.

try printing something after every line in the function so you can find out where the function stops

When you start playing on the studio, things load in lightning-fast, on the other hand when joining a Roblox game server we can’t say the same thing. Your objects load slower than studio when on a Roblox game because they need to be loaded from an external computer. Use :WaitForChild and find other ways to wait for instances to load in.

PS. Type /console in the game chat to see what the error is.

So im adding the waitfor child to my scripts just to test is there a way i could make it like wait for the player to be fully loaded?

I haven’t used CharacterAppearanceLoaded for myself before, but you may check it out in the wiki Player | Roblox Creator Documentation

1 Like

I will try this, but I already have looked at the console and not a single error pops up.