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

Script works in studio but not in game?

Asked by 8 years ago

local Torso = game.Players.LocalPlayer.Character:WaitForChild("Torso") local sound = Instance.new("Sound",Torso) sound.Volume=1 sound.Pitch=1 sound.Name="" sound.Looped=true sound.PlayOnRemove=false local player = game.Players.LocalPlayer local Format = "http://www.roblox.com/asset/?id=##ID##" local frame = script.Parent:WaitForChild("Frame") frame:WaitForChild("Play").MouseButton1Click:connect(function() local input = tonumber(frame:WaitForChild("Input").Text) if input then sound:Stop() sound.SoundId=Format:gsub("##ID##", tostring(input)) sound:Play() end end) frame:WaitForChild("Stop").MouseButton1Click:connect(function() sound:Stop() end)

Why will this not work? P.S. it is a Local script. And this is for a StarterGUI

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

When a LocalScript runs immediately, the Character will likely not exist -- it takes time to load Characters (this is not the case in Test Solo, where scripts actually start a little late)

Thus you want to get the local player's Character something like this:

local player = game.Players.LocalPlayer
-- the Character if it exists, or I'll wait:
local character = player.Character or player.CharacterAdded:wait()

local Torso = character:WaitForChild("Torso")
0
Swaggy, Issue resolved. TechMetal 10 — 8y
0
GOT ANOTHER ISSUE, now it will only play one time. After the player dies it stops working. TechMetal 10 — 8y
0
Do you keep gui on death? or reset? BlueTaslem 18071 — 8y
Ad

Answer this question