Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Works in studio but not game?

Asked by 8 years ago

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)
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 lightpower26 399 — 8y

2 answers

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

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.

0
A return character is a whitespace character, which is all that is required to delimit an 'end' from the next statement. duckwit 1404 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

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"..

Answer this question