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

Is it possible to change an intvalue's value locally on touch?

I am having trouble with getting this to work. I tried a remote event, but it gave all players +1

local part = Instance.new("Part");
part.Parent = workspace;
part.CFrame = CFrame.new(-685.327, 150.022, 163.614);

local enabled = false;
part.Touched:connect(function(hit)
	if game.Players:FindFirstChild(hit.Parent.Name) and game.Players[hit.Parent.Name] == game.Players.LocalPlayer then
		enabled = true;
		wait(0.2);
		part:Destroy();
		hit.Parent.leaderstats.Stars.Value = hit.Parent.leaderstats.Stars.Value+1
		wait(0.3);
		enabled = false;
	end
end)

why

1 comment

0

It must be server sided because leaderstats are server based

1 answer

I used GetPlayerFromCharacter to be able to access leaderstats, it gets the player from who ever touched the part, and then it adds 1 to stars value, then it destroys the part.

part.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		plr.leaderstats.Stars.Value = plr.leaderstats.Stars.Value + 1
		part:Destroy()
	end
end)

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