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
6 years ago
Edited 6 years ago

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

01local rep = game.ReplicatedStorage
02local remote = rep:WaitForChild("ChangeValue")
03 
04debounce = true
05 
06while true do
07    wait(1)
08local plr = game:GetService("Players").LocalPlayer
09local Gui = plr.PlayerGui.Quest:WaitForChild("DOIT")
10local Gui1 = plr.PlayerGui.Quest:WaitForChild("Framo")
11local Humanoid = game.Workspace.ThiefBoss:FindFirstChild("Enemy")
12 
13Humanoid.Touched:Connect(function(hit)
14    local hum = hit.Parent:FindFirstChild("Humanoid")
15    if Humanoid ~= nil and debounce == true then
View all 33 lines...

1 answer

Log in to vote
0
Answered by 6 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

01local rep = game.ReplicatedStorage
02local remote = rep:WaitForChild("ChangeValue")
03local plr = game:GetService("Players").LocalPlayer
04local Gui = plr.PlayerGui.Quest:WaitForChild("DOIT")
05local Gui1 = plr.PlayerGui.Quest:WaitForChild("Framo")
06local Humanoid = game.Workspace.ThiefBoss:FindFirstChild("Enemy")
07 
08local lastTouch
09Humanoid.Touched:Connect(function(hit)
10    local p = game.Players:GetPlayerFromCharacter(hit.Parent)
11    if p then
12        lastTouch = p
13    end   
14end)
15Humanoid.Died:Connect(function()
16    local playerWhoKilled = lastTouch
17    --Do stuff here
18end)
0
Its still changing for every client tacotown2 119 — 6y
0
You need to put it in a serverscript Potatofoox 129 — 6y
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 — 6y
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 — 6y
Ad

Answer this question