local part = script.Parent.Touch local part2 = script.Parent.TouchAgain local ReplicatedStorage = game:GetService("ReplicatedStorage") local AddValue = ReplicatedStorage.Events:WaitForChild("AddValue") part.Touched:Connect(function(Find) local Parent = Find.Parent local humanoid = Parent:FindFirstChildWhichIsA("Humanoid") if humanoid then end end)
everything works apart from the actual things I want it to do.
I am trying to make it so it adds
player.HP.Value = player.HP.Value + 1
however I am doing it in a script and not in a local script and that won't be possible, how can I make it work?
:GetPlayerFromCharacter allows you to get a player from their character model. Use the following code (inside the if humanoid check):
local player = game.Players:GetPlayerFromCharacter(Parent) if player then AddValue:FireClient(player) end
Hope this helped!
You can still access HP.Player.Value from the server, or a script. GetPlayerFromCharacter returns the player associated with the character that touched the part, and from there it's a simple matter of defining the path to your value.
local Players = game:GetService("Players") script.Parent.Touched:Connect(function(Find) local player = Players:GetPlayerFromCharacter(Find.Parent) local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:FindFirstChildWhichIsA("Humanoid") if humanoid then local HP = player:WaitForChild("HP") if HP then HP.Value = HP.Value + 1 print(HP.Value) end end)