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

change location and add point?

I know this may sound like a lot but please help with this. I was wondering how would I make it so when I(or any other Player) walk on a brick, it disappears and teleports to a random location on the map and adds a Point to the leaderboard? The map is 200 by 200. Please help I really need this. :)

1 answer

This would basically be the code for the first part of your question (teleporting the brick):

local Brick = PATH_TO_BRICK --Replace this with your brick
Brick.Touched:connect(function(Obj) --Connects the Touched event to an anonymous function
	Brick.Transparency = 1
	Brick.CFrame = CFrame.new( --Replace the Min and Max in the math.random() with your numbers
						math.random(MinX,MaxX),
						math.random(MinY,MaxY),
						math.random(MinZ,MaxZ)
					)

This would be the code for the second part of your question (giving the player a point):

	if Obj and Obj.Parent then --Making sure the Obj still exists
		local Player = game.Players:GetPlayerFromCharacter(Obj.Parent) --Gets the player from the character
		if Player then
			local PointStat = Player.leaderstats:FindFirstChild("STAT_NAME") --Replace STAT_NAME with the name of the stat
			if PointStat then
				PointStat.Value = PointStat.Value + 1 --Change 1 to how many points you want to award
			end
		end
	end
end)

So the combined code would basically look like this:

local Brick = PATH_TO_BRICK --Replace this with your brick
Brick.Touched:connect(function(Obj) --Connects the Touched event to an anonymous function
	Brick.Transparency = 1
	Brick.CFrame = CFrame.new( --Replace the Min and Max in the math.random() with your numbers
						math.random(MinX,MaxX),
						math.random(MinY,MaxY),
						math.random(MinZ,MaxZ)
					)
	if Obj and Obj.Parent then --Making sure the Obj still exists
		local Player = game.Players:GetPlayerFromCharacter(Obj.Parent) --Gets the player from the character
		if Player then
			local PointStat = Player.leaderstats:FindFirstChild("STAT_NAME") --Replace STAT_NAME with the name of the stat
			if PointStat then
				PointStat.Value = PointStat.Value + 1 --Change 1 to how many points you want to award
			end
		end
	end
end)

Hope this helped!

1 comment

0

It did thanks!

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