Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to fix error :TakeDamage isn't valid member of Player?

player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
Humanoid = game:GetService("Players").LocalPlayer.Character
mouse = player:GetMouse()
if mouse then
mouse.KeyDown:connect(function(key)
if key=="b" then	
	game.ReplicatedStorage.Damage:FireServer(character.Humanoid,15)
end

I tried every method to work but It doesn't work anyways anyone know how to fix it?

I have script in remote event in server scripts

it have (Target and DMG) in the function.

serverside

game.ReplicatedStorage.Damage.OnServerEvent:Connect(function(Target,DMG)
	Target:TakeDamage(DMG)
end)

2 comments

0

Post server codes too

0

Post the real source code. "it have (Target and DMG) in the function." is not the source code.

1 answer

✓ Accepted answer

Remember that the first argument that is passed to your listener is the client who fired the event. So Target was actually the player who fired your event and not what you passed to it. That also means DMG was the humanoid and not the number.

game.ReplicatedStorage.Damage.OnServerEvent:Connect(function(_, Target, DMG)
	--// the player parameter didn't serve a purpose so I used a placeholder variable `_`
	Target:TakeDamage(DMG);
end)

You should also consider using UserInputService.InputBegan rather than mouse.KeyDown since the latter is deprecated.

Sample code

local UserInputService = game:GetService("UserInputService");

UserInputService.InputBegan:Connect(function(input, gpe)
	if (gpe) then
		return; --// Interacted with game engine (e.g. typing in text box, clicked a GUI button); break out of function
	end
	print(input.UserInputType.Name); --// print the input type
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.