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

how do i make it so it only rewards the client that killed the npc?

Asked by
tacotown2 119
5 years ago
Edited 5 years ago

so like its rewarding all clients and i dont want that how do i fix this???

local rep = game.ReplicatedStorage
local remote = rep:WaitForChild("ChangeValue")

debounce = true

while true do
    wait(1)
local plr = game:GetService("Players").LocalPlayer
local Gui = plr.PlayerGui.Quest:WaitForChild("DOIT")
local Gui1 = plr.PlayerGui.Quest:WaitForChild("Framo")
local Humanoid = game.Workspace.ThiefBoss:FindFirstChild("Enemy")

Humanoid.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if Humanoid ~= nil and debounce == true then
        debounce = false
        game.Players:GetPlayerFromCharacter(hit.Parent)
        Humanoid.Died:Connect(function()
            if hit.Parent then
            Gui:TweenSize(UDim2.new(0,227,0,152), Enum.EasingDirection.In, Enum.EasingStyle.Elastic,1,true,nil)
            wait(1)
            Gui.Visible = false
            if Gui.Visible == false then
            Gui1.TextLabel.Text = "Thank you for defeating the Thief Boss"
    remote:FireServer("Quest")
    wait()
    debounce = true
            end
            end
        end)
        end
    end)
end

1 answer

Log in to vote
0
Answered by 5 years ago

You will have to detect who touched the player last so that you know who killed him

This should be in a serverscript and will be something along the lines of

local rep = game.ReplicatedStorage
local remote = rep:WaitForChild("ChangeValue")
local plr = game:GetService("Players").LocalPlayer
local Gui = plr.PlayerGui.Quest:WaitForChild("DOIT")
local Gui1 = plr.PlayerGui.Quest:WaitForChild("Framo")
local Humanoid = game.Workspace.ThiefBoss:FindFirstChild("Enemy")

local lastTouch
Humanoid.Touched:Connect(function(hit)
    local p = game.Players:GetPlayerFromCharacter(hit.Parent)
    if p then
        lastTouch = p
    end    
end)
Humanoid.Died:Connect(function()
    local playerWhoKilled = lastTouch
    --Do stuff here
end)
0
Its still changing for every client tacotown2 119 — 5y
0
You need to put it in a serverscript Potatofoox 129 — 5y
0
You can't put this in a server script, it references LocalPlayer, PlayerGui of the LocalPlayer, a single variable for lastTouch (cannot track multiple players),etc. This is still all client-only code. EmilyBendsSpace 1025 — 5y
0
First of all theres only one enemy who he’s trying to get the lasttouch of hence why its a single variable, secondly i didnt include any of the gui stuff in my answer for that reason, he’ll need to communicate with the client himself Potatofoox 129 — 5y
Ad

Answer this question