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

Player will not die? Please help!

Asked by 5 years ago

So if I killed someone in my game they die on my screen but does not respawn. But on their screen, they see them alive and if they touch me I die and I do not respawn. Please help, thank you.

0
show your code DeceptiveCaster 3761 — 5y
0
I do not have a code, Because I do not know where to start, I don't understand what is happening. Leqtrix 7 — 5y
0
simple, filtering enabled theking48989987 2147 — 5y
0
Ok so the problem is that whatever or however you are killing them, you are doing it from the client, so only you see it RetroGalacticGamer 331 — 5y
View all comments (2 more)
0
Ok so the problem is that whatever or however you are killing them, you are doing it from the client, so only you see it RetroGalacticGamer 331 — 5y
0
@DominusInfinitus See my answer TerrodactyI 173 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

Are you killing players in a LocalScript? If so, it makes sense that only you can see it.

ROBLOX uses a Client-Server Model, which means your client can't affect other players. This means that, rather than your computer telling the server "this player is now dead", you need to ask the server "please make this player dead" and then the server will tell everyone "this player is now dead".

However, this is a bad example. The server should not allow the client to automatically kill people arbitrarily. The server should be the one deciding when someone should or shouldn't be killed. In that case, say we have a sword. This sword is supposed to damage people.

In the sword, there is a LocalScript, a Script, and a RemoteEvent. This RemoteEvent will be the 'Hit event'. A RemoteEvent allows a LocalScript to tell a Script on the server that something happened.

In the LocalScript, there will be something like this:

script.Parent.Equipped:Connect(function(mouse)
    local connection = script.Parent.Activated:Connect(function()
        local target = mouse.Target

        if not target then return end

        local foundHumanoid = target.Parent
                              and target.Parent:IsA('Model')
                              and target.Parent
                                  :FindFirstChildWhichIsA('Humanoid')

        if not foundHumanoid then return end

        script.Parent.Hit:FireServer(foundHumanoid)
    end)

    script.Parent.Unequipped:Wait()

    connection:Disconnect()
end)

In the Script, there will be something like this (if statement split out into multiple lines for readability purposes):

local debounces = {}

local function isInstance(instance)
    return instance
        and type(instance) == 'userdata'
        and getmetatable(instance)
        and instance.ClassName ~= nil
end

script.Parent.Hit.OnServerEvent:Connect(function(player, humanoid)
    if not debounces[player]
    and isInstance(humanoid)
    and humanoid:IsA('Humanoid')
    and humanoid.Parent
    and humanoid.Parent:IsA('Model')
    and humanoid.Parent.PrimaryPart
    and player.Character
    and player.Character.PrimaryPart
    and player.Character.PrimaryPart.CFrame
        :ToObjectSpace(humanoid.Parent.PrimaryPart.CFrame)
        .Position.Magnitude < 3
    then
        debounces[player] = true

        humanoid:TakeDamage(15)

        wait(1)
        debounces[player] = false
    end
end)

Basically, when you hit a player, the LocalScript is telling the server a player was hit. It's that simple.

Then, the script does all the work. It's very important to make sure the client isn't lying, since you can't trust them EVER. The script makes sure that the player's character exists, the enemy's character/humanoid exists, they are close enough to be hit by the sword, and only allows the player to hurt someone else once per second. This is an incredibly safe way to code. Never believe the client. Always implement server logic on the server.

Anyway, hope I helped. Make sure you fire the event when you swipe the sword, or whatever weapon you have (and make sure you know the Humanoid you're trying to damage), and you should be fine.

Comment if you need any extra help, I can edit my answer, but if I helped remember to upvote and accept~

0
I dont think that many checks is ever neccesary to check if a character exists theking48989987 2147 — 5y
0
You don't know what the client is passing in. TerrodactyI 173 — 5y
0
Assuming you do know what the client passes in is one way to invite weird errors/exploits TerrodactyI 173 — 5y
0
Anything the client has touched, you need to rigorously test to ensure it's what you want and something you will allow. TerrodactyI 173 — 5y
View all comments (6 more)
0
first of all, you could just check if the parent of the Humanoid is the player's character and it's a humanoid. I don't really see the need of seeing if the parent of thing sent over has a primary part. theking48989987 2147 — 5y
0
Nor do I see any point in checking the first parameter, as the client doesn't have control over what is sent over as the 1st parameter theking48989987 2147 — 5y
0
but other than that, pretty great explanation theking48989987 2147 — 5y
0
player is the Player object, humanoid is the parameter passed as the client. I don't check that the first parameter is a Player, I only check to make sure they have a character. Meanwhile, I check everything about the second TerrodactyI 173 — 5y
0
Passed BY the client, sorry TerrodactyI 173 — 5y
0
The PrimaryPart thing is for CFrame to prevent errors. TerrodactyI 173 — 5y
Ad

Answer this question