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

Damage system only visible to the first person?

So, I've been making a combat system for about a week now. And my friend and I decided to test the actual game already. But, it is only I who could see him dealt damage and only him that could see me took damage. What should we do, Sir/Ma'am? Thanks much.

Local Script under StarterPlayerScript:

local UIS = game:GetService("UserInputService")

local function attack()
	--block of codes
end

UIS.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Q then
			attack()
		end
end)

1 answer

✓ Accepted answer

There's a thing called client-server model. The thing you experienced is different, because that's the client. Each computer's screen is different, and there are differences. The server, however, has the change affected to every computer. So you'll need to use a remote event to see your work.

Local Script

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.Q then
            game.ReplicatedStorage.RemoteEvent:FireServer() --This fires to the server.
        end
end)

Server Script

local function attack(player)
	--You'll need to change your attack code a bit if it uses something like LocalPlayer.
end
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(attack)

3 comments

0

Uhhh, I actually have 4 different functions/attacks. Do I have to have 4 ServerScript and 4 RemoteEvent?

0

No. Not at all. Optimisation and Common sense is key.

0

Thanks, Sir.

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