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

How would I make all scripts I made that work in studio, work in play mode?

Heres an example I made which wouldn't work in play mode. Am I doing everything wrong? Most of my scripts don't work in play mode.

-----------------------------------------------
local user = game.Players.LocalPlayer -- the player
local character = user.Character -- the character
local Tool = script.Parent -- script.parent >:o
local reload = 3 -- reload time between each drink
local debounce = true -- no touchy
local oneuse = false-- if its a one-use item
	local timebeforefinish = 3
-----------------------------------------------
function activated()
	if not Tool.Enabled  then
		return
	end
	if debounce == true then
		local anim = character.Humanoid:LoadAnimation(Tool.drink)
		anim:Play()
		debounce = false
		Tool.Handle.gulp:play() -- drink sound
		wait(2)
		character.Humanoid.Health = character.Humanoid.Health + 50
		--- nope ---
		if oneuse == true then
			onusee()
		else
		wait(reload)
		debounce=true
		end
	end
end

function equip()
	Tool.Handle.equip:play() 
end

function unequip()
								
end
function onusee()
	wait(2)
	Tool:Destroy()
end
Tool.Activated:connect(activated)
Tool.Equipped:connect(equip)
Tool.Unequipped:connect(unequip)

7 comments

1

is this a local script

0

Depends on if you're using LocalScripts or ServerScripts. Here are a couple blog articles that will help explain the difference between online and server mode as well as LocalScripts versus ServerScripts.

0

explain a little bit more... any errors or anything???

0

This is a local script and yes its inside of a tool.

0

Would you like me to give you a better version of your script to work in studio mode as another answer?

0

Also if you are using a local script, then I would recommend using local functions.

1 answer

✓ Accepted answer

It depends on what scripts your using, how you define your variables, and how you layout your scripts.

For example, in a Gui, you cannot reference anything outside of the frame the Gui is in unless you use it a certain way.

Proper Way to Reference Outside of the Frame


-- This script would work in ANY mode, even servers or game mode.

local players = game:GetService("Players")
local player = players.LocalPlayer

local gui = player:WaitForChild("PlayerGui")
local nameofgui = gui:WaitForChild("TheName")
local referencee = nameofgui:WaitForChild("TheName")

function ()
 -- Whatever your function is
end

So basically, say your script is in a frame inside of a gui and you want to reference something outside of it, you would have to go through the player, then the playerGui, and finally the gui inside of the playerGui.

Here is an example of what NOT to do!


-- This script would ONLY work in studio mode!

local players = game.Players.LocalPlayer -- An acceptable way of referencing players

local referencee = script.Parent.Parent.Item
--[[
or
local referencee = script.Parent.Parent.Parent.Item
]]--

Hoped this helped you out!

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