generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: OnTouch problem, :InvokeClient() --player nil value?

Previous Thread :: Next Thread 
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 01:24 PM
Trying to make a player play an animation when they touch a brick but it says:
"attempt to index local 'player' (a nil value)"


This is part of the code:

script.Parent.Touched:connect(function(part)
if part.Parent ~= nil and part.Parent:FindFirstChild("Humanoid") then
local Humanoid = part.Parent:FindFirstChild("Humanoid")
if not Humanoid:FindFirstChild("Hit") then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
print('player')
local Hit = Hit:Clone()
local RemoveScript = Hit:WaitForChild("Remover")
Hit.Parent = Humanoid
RemoveScript.Disabled = false
Humanoid.Health = Humanoid.Health - HealthLoss
Remote:InvokeClient(player)
print('Invoked')



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 01:25 PM
hmm..



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 01:36 PM
I don't want to bump this thread too fast, but I know there is probably a easy solution and this is really slowing me down. I'm going to mess around with the script a little more.


I also noticed i wrote print('player") instead of print(player) so imma see if it still gives me the nil error for that.



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 01:37 PM
When I do print(player) it prints Player which is the correct name...weird



Report Abuse
gskw is not online. gskw
Joined: 05 Jan 2013
Total Posts: 1364
03 Apr 2016 01:39 PM
Use InvokeClient(player, player)
Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 01:42 PM
Wtf...How does that work? Can you explain?



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 01:43 PM
I mean... it worked for me, but how? xD



Report Abuse
intrinsik is not online. intrinsik
Joined: 23 Oct 2013
Total Posts: 681
03 Apr 2016 01:45 PM
Usually in Remote F/Es, there's an automatically forced player field inputted without any user choice involved
Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 01:48 PM
then why was it printing nil when i only put one?
and why do i need 2?



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 01:56 PM
Ok so what I'm trying to do is freeze the player and make them play an animation.
For some reason, it never prints ('Invoked') with the function you gave which I'm assuming means its still waiting for a response from the client. I thought return was suppose to give it a response but its not working.

This is the Client Script:

game.ReplicatedStorage:WaitForChild("Remotes")
local Remote = game.ReplicatedStorage.Remotes:WaitForChild("AnimationPlayer")

Remote.OnClientInvoke = function(player)
-- Load assets --
local Character = player.Character or player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Humanoid:WaitForChild("Stun")
local AnimTrack = Humanoid:LoadAnimation(Animation)
local StunTime = Humanoid:WaitForChild("Hit")

AnimTrack:Play()
repeat wait() until not StunTime:IsDescendantOf(Humanoid)
print('StunTime over')
AnimTrack:Stop()
print('Animation Stopped')
return player, player
end



Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
03 Apr 2016 02:01 PM
might not be what you want but i reformatted your code to what made sense to me

--server script

local re = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local healthLoss = 20

script.Parent.Touched:connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human then
local player = game.Players:GetPlayerFromCharacter(human.Parent)
if player then
local remover = hit:WaitForChild("Remover")
remover.Parent = human
remover.Disabled = false
human.Health = human.Health - healthLoss
re:FireClient(player)
end
end
end)


Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 02:07 PM
Why RE bro? xD
Anyway I can't use RE because I need to wait till the client finishes and RE doesn't wait.

If you need the full code here it is(I don't think its necessary though):

-- Server
local HealthLoss = 35
local Hit = script.Parent:WaitForChild("Hit")
game.ReplicatedStorage:WaitForChild("Remotes")
local Remote = game.ReplicatedStorage.Remotes:WaitForChild("AnimationPlayer")

script.Parent.Touched:connect(function(part)
if part.Parent ~= nil and part.Parent:FindFirstChild("Humanoid") then
local Humanoid = part.Parent:FindFirstChild("Humanoid")
if not Humanoid:FindFirstChild("Hit") then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
print(player)
local Hit = Hit:Clone()
local RemoveScript = Hit:WaitForChild("Remover")
local Torso = part.Parent:WaitForChild("Torso")
Hit.Parent = Humanoid
RemoveScript.Disabled = false
Humanoid.Health = Humanoid.Health - HealthLoss
Torso.Anchored = true
Remote:InvokeClient(player, player)
print('Invoked')
repeat wait() until not Hit:IsDescendantOf(Humanoid)
print('StunTime ended')
Torso.Anchored = false
else
return
end
end
end)


-- Client

game.ReplicatedStorage:WaitForChild("Remotes")
local Remote = game.ReplicatedStorage.Remotes:WaitForChild("AnimationPlayer")

Remote.OnClientInvoke = function(player)
-- Load assets --
local Character = player.Character or player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Humanoid:WaitForChild("Stun")
local AnimTrack = Humanoid:LoadAnimation(Animation)
local StunTime = Humanoid:WaitForChild("Hit")

AnimTrack:Play()
repeat wait() until not StunTime:IsDescendantOf(Humanoid)
print('StunTime over')
AnimTrack:Stop()
print('Animation Stopped')
return player, player
end



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 02:11 PM
If anyone reading this was thinking 'tl;dr' then basically all I want is a way to give a response back to the server. return isnt working for me.



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 02:43 PM
thx for help though @tick

I might just use 2 remote events so I can fire back to the server once the client script finishes, I wanna see if I can do it without all of that though xD



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 02:47 PM
helppppp qq



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 02:54 PM
remotefunctions so annoyinggg omggggggg



Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
03 Apr 2016 02:55 PM
ok first off what the hell are you trying to do?


Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 03:05 PM
I'm trying to freeze the player and make them play an animation onTouch



Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
03 Apr 2016 03:07 PM
okay is this like freeze tag or something?


Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 03:07 PM
mybad for replying late, was trying to figure out:
1. Why it needs another argument named folder even though its calling from the server
2. Why doesn't it work with the one I gave alone?
3. Why the clientscript isn't giving a response back to the server



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 03:11 PM
No working on a attack move for a monster which is a ice move as you can guess.

(!!!!UNNECESSARY READING AHEAD!!!!!)

When its health lowers a certain amount then it uses a bindablefunction to bring a model to the monster and the model uses cframe and stuff to raise under the ground, like some ice underground spike attack. And theres a Damage brick in that model which basically it checks one part, that one part is the primarypart which is the size of the whole model and is uncancollid. And so it checks when that block is touched and when it is touched, it does the function of freezing which anchors the torso then fires to the client which does the animation which then gives a response back to the server which unanchors the torso.



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 03:15 PM
Just incase you are still unsure what I need,

Basically all I want is a way to give a response back to the server. return isnt working for me.

I posted the ClientScript in this thread somewhere xD. I think twice actually, the full thing.



Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 03:24 PM
Q-Q



Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
03 Apr 2016 03:42 PM
Okay again. You don't need a remote function. When the anim track is over, fire the server again so it knows to tell the torso to be unacnhored instead of using remote functions.

--server script

local HealthLoss = 35
local Hit = script.Parent:WaitForChild("Hit")
local Remote = game.ReplicatedStorage.Remotes:WaitForChild("AnimationPlayer")

script.Parent.Touched:connect(function(part)
local Humanoid = part.Parent:FindFirstChild("Humanoid")
if Humanoid and not Humanoid:FindFirstChild("Hit") then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
local Hit = Hit:Clone()
Hit.Parent = Humanoid
local RemoveScript = Hit:WaitForChild("Remover")
local Torso = Humanoid.Parent:WaitForChild("Torso")
RemoveScript.Disabled = false
Humanoid.Health = Humanoid.Health - HealthLoss
Torso.Anchored = true
Remote:FireClient(player)
repeat wait() until not Humanoid:FindFirstChild("Hit")
Torso.Anchored = false
end
else
return
end
end)

--local script

local Remote = game.ReplicatedStorage.Remotes:WaitForChild("AnimationPlayer")
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")

Remote.OnClientEvent:connect(function()
local Animation = Humanoid:WaitForChild("Stun")
local AnimTrack = Humanoid:LoadAnimation(Animation)
local StunTime = Humanoid:WaitForChild("Hit")
AnimTrack:Play()
repeat wait() until not Humanoid:FindFirstChild("Stun")
AnimTrack:Stop()
end)


Report Abuse
eRanged is online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
03 Apr 2016 03:57 PM
You didnt fire back to the server, but I know how to do that. I just want to wait until the animation stop before moving them again because it's going to look like gliding.



Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image