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

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

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

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)

4 comments

0

Its still changing for every client

0

You need to put it in a serverscript

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.

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

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