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

how to change value through script?

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?

2 answers

: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!

2 comments

0

the check if humanoid code already works, I need help setting up the system that adds value to the value inside of the player, but I can't as its a script and not a local script. I can't access game.Players.LocalPlayer.HP.Value

0

AddValue:FireServer(number) works but only from LocalScript, how to do it from just a script?

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)

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