Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Damage system only visible to the first person?

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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)
0
Uhhh, I actually have 4 different functions/attacks. Do I have to have 4 ServerScript and 4 RemoteEvent? Dehydrocapsaicin 483 — 3y
0
No. Not at all. Optimisation and Common sense is key. Dovydas1118 1495 — 3y
0
Thanks, Sir. Dehydrocapsaicin 483 — 3y
Ad

Answer this question