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: Help with RemoteFunctions

Previous Thread :: Next Thread 
storm_xst is not online. storm_xst
Joined: 27 Jul 2016
Total Posts: 1205
29 Oct 2016 10:40 AM
On the server

-

game.ReplicatedStorage:WaitForChild'dmg'.OnServerInvoke=function(p,c)
print ('yes')
pcall(function()
print ('yes2')
workspace[c]:WaitForChild'Humanoid':TakeDamage(math.random(15,50))
end)
end

-

On the client

local function fire()
pcall(function()
local gunhandle = workspace.CurrentCamera.Magnum.Muzzle
local ray = Ray.new(gunhandle.CFrame.p, (game.Players.LocalPlayer:GetMouse().Hit.p - gunhandle.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, game.Players.LocalPlayer.Character, false, true)
if part then
local char=part.Parent
if game.Players:FindFirstChild(char) then
print ('hit')
game.ReplicatedStorage.dmg:InvokeServer(game.Players.LocalPlayer,char.Name)
end
end
-

Ray is being casted on the client, it's visible. Even if it visually hits the player, nothing happens.

I am using a StarterCharacter, all parts inside are direct children to the character, and there is a humanoid inside of the part.

"hit", "yes1", and "yes2" are not being printed, and of course the character is not being damaged. Being tested on a local server with 2 players.
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
29 Oct 2016 11:02 AM
So, you were trying to do a few things incorrectly

1: You're using a RemoteFunction when you should use a RemoteEvent.
2: You tried to do game.Players:FindFirstChild(char) when really you should either use game.Players:FindFirstChild(char.Name) or game.Players:GetPlayerFromCharacter(char)
3: Similarly, as above, you tried to find workspace[c], which doesn't exist unless workspace is a dictionary with entry [c] = someVal, or c is a key, which it's neither.
4: You don't need to send the player as the first argument when firing the server, it automatically comes with.


-- server script
game.ReplicatedStorage:WaitForChild("DmgEvent").OnServerEvent:connect(function(p,c)
print("DmgEvent received:",p.Name,c.Name)
local hum = c:FindFirstChild("Humanoid")
hum:TakeDamage(math.random(15,50)
end)


-- local script
player = game.Players.LocalPlayer
mouse = player:GetMouse()
function Fire()
local gunhandle = workspace.Currentcamera.Magnum.Muzzle
local ray = Ray.new(gunhandle.CFrame.p,(mouse.Hit.p - gunhandle.CFrame.p).unit *300)
local part,position = workspace:FindPartOnRay(ray,player.Character,false, true)
if part and game.Players:GetPlayerFromCharacter(part.Parent then)
print("The ray hit a real character")
game.ReplicatedStorage.DmgEvent:FireServer(part.Parent)
end
end




Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
29 Oct 2016 11:03 AM
I missed a parenthesis on the :TakeDamage() line


Report Abuse
storm_xst is not online. storm_xst
Joined: 27 Jul 2016
Total Posts: 1205
29 Oct 2016 11:34 AM
Merci bien, Soybeen!
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