Use a LocalScript
When you create a variables outside of the event, that variable was randomized just in a first time. After that is the same result because the value of this variable is the result of the first randomise.
local randomMsg = msgTable[math.random(1, #msgTable)]
To fix this put the randomise on the Event
game:GetService('Players').LocalPlayer.Character.Humanoid.Died:Connect(function()
text.Text = msgTable[math.random(1, #msgTable)]
frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Quad",0.5,true)
wait(1.5)
frame.Position = UDim2.new(0.5,0,-0.5,0)
end)
I recommand found the ScreenGui with the PlayerService (Players) and not with the Parent of the Instance.
local PlayerService = game:GetService('Players')
local Player = PlayerService.LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')
local ScreenGui = PlayerGui:WaitForChild('ScreenGui')
local frame = ScreenGui:WaitForChild('Frame')
local text = frame:WaitForChild('TextLabel')
Use WaitForChild to prevent errors.
Your script now:
local PlayerService = game:GetService('Players')
local Player = PlayerService.LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')
local ScreenGui = PlayerGui:WaitForChild('ScreenGui')
local frame = ScreenGui:WaitForChild('Frame')
local text = frame:WaitForChild('TextLabel')
local msgTable = {"You died.", "You died!", "You died?", "You died...", "Haha noob", "Get rekt", "Get shrekt", "Get shrekt", "Better luck next time", "That's one more death added...", "Counting failures...", "Error sytem shutting down.", "What happened?", "Error 404", "E", "Huh..", "Oh."}
Player.Character.Humanoid.Died:Connect(function()
text.Text = msgTable[math.random(1, #msgTable)]
frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Quad",0.5,true)
wait(1.5)
frame.Position = UDim2.new(0.5,0,-0.5,0)
end)
Hope this help, to more questions put bellow on commentaries.
1 comment
At line 30 you need Udim2 For setting Position for example: Udim2.new(0.5,0,-0.5,0)