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

Works in studio but not game?

I did the code correcty, is it ROBLOX? It works in studio, but not a clean game.

heres the model: http://www.roblox.com/ROBLOX-Media-Player-item?id=342748215

game: http://www.roblox.com/games/342750211/rmp-testing

--EpicWalnut5
function click()
	script.Parent.Parent.Parent.Parent.Parent.Sound:Stop()
	script.Parent.Parent.Parent.Parent.Parent.Sound.SoundId = 'rbxassetid://251979407'
	script.Parent.Parent.Parent.Parent.Parent.Sound:Play()
	script.Parent.Parent.Parent.frame.music.Image = 'rbxassetid://339386472'
	script.Parent.Parent.Parent.frame.Text = ' '
end
script.Parent.MouseButton1Click:connect(click)

2 comments

0

Hmm... I know what you mean, I've actually had this problem before. It just seemed to clone itself. Try adding a few waits

2 answers

I know you may call me crazy, but after line 8, press Enter, making a 9 a space between 8 and 10. I remember that connection lines need to be at least 1 space away.

1 comment

0

A return character is a whitespace character, which is all that is required to delimit an 'end' from the next statement.

First of all, it's a gui button, so you don't need to use a "function"; and maybe adding :WaitForChild() in each line, or defining variables may hope majorly.

Your code is ugly, un-organized and plain old and shifty.. (No offense!)

--EpicWalnut5
function click()
script.Parent.Parent.Parent.Parent.Parent.Sound:Stop()
script.Parent.Parent.Parent.Parent.Parent.Sound.SoundId = 'rbxassetid://251979407'
script.Parent.Parent.Parent.Parent.Parent.Sound:Play()
script.Parent.Parent.Parent.frame.music.Image = 'rbxassetid://339386472'
script.Parent.Parent.Parent.frame.Text = ' '
end

script.Parent.MouseButton1Click:connect(click)

So here's (hopefully) the fixed version, organized and spacious version; with helpful taglines aka comments to hopefully help you understand what's going on with each line of code.

I hope this helped and will also help you in the future, regards, Asperanator.

Fixed version(hopefully):


--Author: EpicWalnut5
--Tweaked / Fixed by: Asperanator

--[ Variables ]--

local button = script.Parent
local sound = script.Parent.Parent.Parent.Parent:WaitForChild("Sound") -- Wait's for "Sound" to exist 
local frame = script.Parent.Parent:WaitForChild("frame") -- Waits for "frame" to exist
local music = frame:WaitForChild("music") -- Waits for "music to exist"

--[ Function ]--

button.MouseButton1Down:connect(function() -- When "button" is clicked by left or right click do the following content inside the function

sound:Stop() -- Stops the sound completely
	sound.SoundId = 'rbxassetid://251979407' -- Inserting a new songId
		sound:Play() -- Plays the sound

music.Image = 'rbxassetid://339386472' -- Inserting an image asset
	frame.Text = " " -- Making "frame.text" have no text

end)

If that doesn't work, add .Parent in the frame & sound variable.

Hope this helped if not; contact me on ROBLOX: Asperanator - http://www.roblox.com/users/85640404/profile

And if this helped please give it the "arrow up", or "thumbs up"..

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