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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 27 Jul 2016 |
| Total Posts: 1205 |
|
| |
|