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

My script/GUI wont work after death?

Asked by 8 years ago
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")

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)

Is there something wrong here, or is it the GUI? It doesn't work after death.

0
local character = player.Character, remove last part of it. Also add a repeat wait() until player.Character above it. TheDeadlyPanther 2460 — 8y
0
I'm a bit baffled, why are you using gsub just for a SoundId? Shawnyg 4330 — 8y
0
I can't get what you're saying panther, could you give me a example? TechMetal 10 — 8y

1 answer

Log in to vote
0
Answered by
DevArk 50
8 years ago

what panther means (and I agree with him) :

local player = game.Players.LocalPlayer

-- the Character if it exists, or I'll wait:
repeat wait() until player.Character
local character = player.Character

local Torso = 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)
Ad

Answer this question