games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 06:33 PM |
After a recent roblox update, the GetPlayerFromCharacter function has stopped working completely. A music script of mine now doesn't work because of this. Here is the critical line:
local playerPart = game.Players:GetPlayerFromCharacter(hit.Parent)
For some reason, the console always says that playerPart is nil. It works in studio but not in-game. Can anyone explain why this is suddenly happening? |
|
|
| Report Abuse |
|
|
|
| 18 Aug 2016 06:34 PM |
function getPlayerFromCharacter(char) for _,v in pairs(game.Players:GetPlayers()) do if v and v.Character and v.Character == char then return v end end return nil end
--use this instead |
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 18 Aug 2016 06:38 PM |
| Are you certain that Hit.Parent is a legitimate character model? This method does return nil if an invalid character is given as the argument. |
|
|
| Report Abuse |
|
|
frriend
|
  |
| Joined: 07 Feb 2010 |
| Total Posts: 577 |
|
|
| 18 Aug 2016 06:39 PM |
Just use
game.Player:FindFirstChild(char.Name) |
|
|
| Report Abuse |
|
|
games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 06:42 PM |
Here is the entire script that isn't working:
script.Parent.Touched:connect(function(hit) local playerPart = game.Players:GetPlayerFromCharacter(hit.Parent) if playerPart == nil then print("Error! Player captured is nil for some reason.") end if (playerPart.bgm1.IsPaused == true) then playerPart.bgm2:Stop() playerPart.bgm3:Stop() playerPart.bgm4:Stop() playerPart.bgm5:Stop() playerPart.bgm13:Stop() playerPart.bgm16:Stop() playerPart.bgm1:Play() playerPart.bgm15:Play() end end)
I need a solution where the game can detect a player by the model that touches this brick. |
|
|
| Report Abuse |
|
|
frriend
|
  |
| Joined: 07 Feb 2010 |
| Total Posts: 577 |
|
|
| 18 Aug 2016 06:42 PM |
script.Parent.Touched:connect(function(hit) local playerPart = game.Players:FindFirstChild(hit.Parent.Name) if playerPart == nil then print("Error! Player captured is nil for some reason.") end if (playerPart.bgm1.IsPaused == true) then playerPart.bgm2:Stop() playerPart.bgm3:Stop() playerPart.bgm4:Stop() playerPart.bgm5:Stop() playerPart.bgm13:Stop() playerPart.bgm16:Stop() playerPart.bgm1:Play() playerPart.bgm15:Play() end end)
|
|
|
| Report Abuse |
|
|
|
| 18 Aug 2016 06:43 PM |
pcall(function() local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then --is a player else --is something else end end)
pcall will just get rid of any errors but is not necessary |
|
|
| Report Abuse |
|
|
games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 06:49 PM |
@Frriend
Your solution is clever but unfortunately does not fix anything. The game still reports the PlayerPart as nil. How odd. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 18 Aug 2016 06:51 PM |
Post your code, it's probably just wrong.
|
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 18 Aug 2016 06:53 PM |
script.Parent.Touched:connect(function(hit) if not (hit and hit.Parent) then return end local playerPart = game.Players:FindFirstChild(hit.Parent) if (not playerPart) then return end if (playerPart.bgm1.IsPaused == true) then playerPart.bgm2:Stop() playerPart.bgm3:Stop() playerPart.bgm4:Stop() playerPart.bgm5:Stop() playerPart.bgm13:Stop() playerPart.bgm16:Stop() playerPart.bgm1:Play() playerPart.bgm15:Play() end end)
|
|
|
| Report Abuse |
|
|
games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 06:53 PM |
Basically, on player entry, the game "injects" sounds into the player:
game.Players.PlayerAdded:connect(function(player) wait(5)
local bgmusic13 = Instance.new("Sound", player) bgmusic13.Name = "bgm13" bgmusic13.Looped = true bgmusic13.Pitch = 1 bgmusic13.Volume = 0.5 bgmusic13.SoundId = "http://www.roblox.com/asset/?id=346027497" --waves bgmusic13:Play()
end)
The code I posted above then activates when a player touches a brick. It should be fairly stright forward. |
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 18 Aug 2016 06:53 PM |
| Forgot to also comment on it, but you have to add in checks to filter out parts that hit and that do not actually belong to a player. |
|
|
| Report Abuse |
|
|
games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 06:58 PM |
@Xsitsu
That makes sense. However, although your code stops the errors, the music still does not change upon touching the block. |
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 18 Aug 2016 07:04 PM |
| Is it a player that is touching the block? Can you link me to the game in question where this is not working correctly? |
|
|
| Report Abuse |
|
|
games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 07:09 PM |
@Xsitsu
Yes, this script goes into a brick, and the player model touches it. What sort of thing are you looking for? |
|
|
| Report Abuse |
|
|
games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 07:15 PM |
Like I said before, it is very odd that the last Roblox update broke this script which had worked up until then. The GetPlayerFromCharacter function should not have been functionally altered. I suspect that, if anything, this might have something to do with it:
http://blog.roblox.com/2016/08/security-update/
I have a feeling that this precaution might have disabled this function, but I don't know. |
|
|
| Report Abuse |
|
|
|
| 18 Aug 2016 07:16 PM |
function getPlayerFromCharacter(char) for _,v in pairs(game.Players:GetPlayers()) do if v and v.Character and v.Character == char then return v end end return nil end
just use this already replied checks every player and sees if the characters are the same |
|
|
| Report Abuse |
|
|
|
| 18 Aug 2016 07:18 PM |
are you even checking what's touching the part
it can be touching the baseplate and throw that error
you need to check that what's touching it is a character
Formerly xXTheRobotXx, add 13,349 posts |
|
|
| Report Abuse |
|
|
games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 07:22 PM |
@Thedailyblarg
Here is my updated touch script:
function getPlayerFromCharacter(char) for _,v in pairs(game.Players:GetPlayers()) do if v and v.Character and v.Character == char then return v end end return nil end
script.Parent.Touched:connect(function(hit) if not (hit and hit.Parent) then return end local playerPart = getPlayerFromCharacter(hit.Parent) if (not playerPart) then return end if playerPart == nil then print("Error! Player captured is nil for some reason.") end if (playerPart.bgm1.IsPaused == true) then playerPart.bgm2:Stop() playerPart.bgm3:Stop() playerPart.bgm4:Stop() playerPart.bgm5:Stop() playerPart.bgm13:Stop() playerPart.bgm16:Stop() playerPart.bgm1:Play() playerPart.bgm15:Play() end end)
I'm sorry, but it still does not work. It has been working in studio, but not in-game. This is really starting to bug me. |
|
|
| Report Abuse |
|
|
|
| 18 Aug 2016 07:28 PM |
script.Parent.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") then local playerPart = game.Players:GetPlayerFromCharacter(hit.Parent) print(playerPart.Name) if (playerPart.bgm1.IsPaused == true) then playerPart.bgm2:Stop() playerPart.bgm3:Stop() playerPart.bgm4:Stop() playerPart.bgm5:Stop() playerPart.bgm13:Stop() playerPart.bgm16:Stop() playerPart.bgm1:Play() playerPart.bgm15:Play() end end end)
Formerly xXTheRobotXx, add 13,349 posts |
|
|
| Report Abuse |
|
|
games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 07:34 PM |
@Lord_Narwhal
That exact script also fails to work in-game. Bizzare. I'm starting to suspect that the sound injection script may not be working correctly (posted above), or that Roblox seriously screwed up something. Although the injector script DOES start playing the music on enter, so I really don't know. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 18 Aug 2016 07:35 PM |
what the hell are you people doing
local part = script.Parent
part.Touched:connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then print(player.Name) end end)
|
|
|
| Report Abuse |
|
|
games4pc
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 616 |
|
|
| 18 Aug 2016 07:39 PM |
@TimeTicks
That's essentially the same thing that we've already posted. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 18 Aug 2016 07:40 PM |
not even close. daily posting some bs function and lord just trolling around not even fixing the ugly ass script. kms
|
|
|
| Report Abuse |
|
|
|
| 18 Aug 2016 07:43 PM |
script.Parent.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") then local playerPart = game.Players:GetPlayerFromCharacter(hit.Parent) print(playerPart.Name)--check if this prints if (playerPart.bgm1.IsPaused == true) then local stop = {2,3,4,5,13,16} local play = {1,15} for i,v in next,stop do playerPart["bgm"..v]:Stop() end for i,v in next,play do playerPart["bgm"..v]:Play() end end end end)
i'm skeptical about the IsPaused check
are you legitimately pausing it in another part of code
Formerly xXTheRobotXx, add 13,349 posts |
|
|
| Report Abuse |
|
|