|
| 17 Jun 2016 09:09 AM |
I am making a DJ GUI for a party place and I'm trying to figure out why it won't work and I think that the problem has to do with RemoteEvents.
Client Script: --[[ DJ CONTROLLER SCRIPT: Creator: Fishguy100 Date: 6/16/2016 Time: 1:42 Description: Handles the DJ GUI and adds functionality to it. --]]
math.randomseed(tick()) -- Changing the randomizations seed
--\\ Services local Lighting = game:GetService("Lighting") local ReplicatedStorage = game:GetService("ReplicatedStorage");
--\\ Tables local Songs = { {398582633,"My House"}; {162555471,"Turn down for what"}; {142376088,"Raining Tacos"}; {213689483,"Honey I'm Good"}; {413885541,"This is what you came for"}; {342189621,"Cheap Thrills"}; };
--\\ The ScreenGui itself local self = script.Parent;
--\\ The background frame that holds all buttons and such local Base = self:WaitForChild("Base");
--\\ The CurrentSong frame and it's contents local CurrentSong = Base:WaitForChild("CurrentSong"); local SongName = CurrentSong:WaitForChild("SongName"); local rAmbient = CurrentSong:WaitForChild("R"); local gAmbient = CurrentSong:WaitForChild("G"); local bAmbient = CurrentSong:WaitForChild("B");
--\\ Time Stuff local TimeLeftBar = Base:WaitForChild("TimeLeftBar"); local Bar = TimeLeftBar:WaitForChild("Bar"); local TimeElapsed = Base:WaitForChild("TimeElapsed"); local TotalTime = Base:WaitForChild("TotalTime");
--\\ RemoteEvents local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");
--\\ Buttons local StartButton = Base:WaitForChild("StartButton");
--\\ Value Holders local LastSong
--\\ Functions local function PickSong() local C = Songs[math.random(1,#Songs)] if C[1] ~= LastSong then LastSong = C[1] return C else return PickSong() end end
function SecondsToMinutes(seconds) local SecondsLeft = seconds%60 local MinutesLeft = math.floor(seconds/60) if SecondsLeft <= 0 then SecondsLeft = "00" elseif SecondsLeft <= 9 then SecondsLeft = "0"..tostring(SecondsLeft) else SecondsLeft = tostring(SecondsLeft) end return tostring(MinutesLeft) .. ":" .. SecondsLeft end
local function Cycle() local ChosenSong = PickSong() RemoteEvent:FireServer(ChosenSong[1])
wait(.5)
local Sound = workspace:FindFirstChild("Sound") and workspace:FindFirstChild("Sound").IsPlaying and workspace:FindFirstChild("Sound") or workspace:WaitForChild("Sound")
SongName.Text = ChosenSong[2] Sound:Play() wait(1) local Length = math.floor(Sound.TimeLength) TotalTime.Text = SecondsToMinutes(Length) while Sound.IsPlaying do local TimePlayed = math.floor(Sound.TimePosition) TimeElapsed.Text = SecondsToMinutes(TimePlayed) Bar.Size = UDim2.new(TimePlayed/Length,0,1,0) wait() end Cycle() end
--\\ Once start button is pressed StartButton.MouseButton1Down:connect(function() StartButton:Destroy() Cycle() end)
Server Script:
--\\ Services local ReplicatedStorage = game:GetService("ReplicatedStorage"); local Players = game:GetService("Players");
--\\ RemoteEvents local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");
--\\ Binding to server events
RemoteEvent.OnServerEvent:connect(function(...) local Table = {...} local Sound = Instance.new("Sound",workspace) Sound.SoundId = "http://www.roblox.com/asset/?id="..tonumber(Table[1]) Sound.Looped = false Sound:Play() spawn(function() wait(Sound.TimeLength) Sound:Stop() Sound:Destroy() end) end)
And here's the error I get: 10:07:12.440 - ServerScriptService.Server:14: attempt to concatenate a nil value
How do I fix this?!
|
|
|
| Report Abuse |
|
|
|
| 17 Jun 2016 09:36 AM |
pretty sure the error has nothing to do with the remoteevents the main thing causing the problem is that the "tonumber(Table[1])" part is nil, and you are concatenating it |
|
|
| Report Abuse |
|
|
|
| 17 Jun 2016 09:43 AM |
ok, found a possible solution: the OnServerEvent has 2 arguments: Player, and whatever else arguments you fired the server with (e.g a,b = 1,2 re:FireServer(a,b)) when you do this:
RemoteEvent.OnServerEvent:connect(function(...) local Table = {...}
you are putting the first argument (player) into the table too. so player = table[1].
the corrected script is:
--\\ Services local ReplicatedStorage = game:GetService("ReplicatedStorage"); local Players = game:GetService("Players");
--\\ RemoteEvents local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");
--\\ Binding to server events
RemoteEvent.OnServerEvent:connect(function(p,...) -- you can also remove p and replace "Table[1]" with "Table[2]" local Table = {...} local Sound = Instance.new("Sound",workspace) Sound.SoundId = "http://www.roblox.com/asset/?id="..tonumber(Table[1]) Sound.Looped = false Sound:Play() spawn(function() wait(Sound.TimeLength) Sound:Stop() Sound:Destroy() end) end) |
|
|
| Report Abuse |
|
|
|
| 17 Jun 2016 10:15 AM |
Either way, it still doesn't work.
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
|
| 17 Jun 2016 04:22 PM |
BUMP 4 NEVER THOUGHT I'D GET THIS FAR...
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 17 Jun 2016 04:28 PM |
I WONT STOP BUMPING UNTIL I GET AN ANSWER SO... BUMP 7 HOPEFULLY LEADS TO HEAVEN
|
|
|
| Report Abuse |
|
|
|
| 17 Jun 2016 04:29 PM |
BUMP 8 IF I DONT GET AN ANSWER ILL WANT TO JUMP A GATE
|
|
|
| Report Abuse |
|
|
| |
|
| |
|