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

How to fix this script??

local settengs = script.Settings
--Identified the folder containing our stats
local yPoints1 = settengs.Stat01.Value
local amount1 = settengs.Stat01Amount.Value
local waittime = settengs.WaitTime.Value
--Identified the stats
local ting = 0
--Debouncer

function OnTouch(Touched)
(script.Parent.Touched:connect(OnTouch)

	if ting == 0 then
	ting = 1
	local Touchy = Touched.Parent:FindFirstChild("Humanoid") 

	if Touchy ~= nil then --If the toucher is a humanoid then proceed

		local Player = game.Players:GetPlayerFromCharacter(Touched.Parent) 
		local stats = Player:findFirstChild("leaderstats") 

		if stats ~= nil then
			local StatToIncrease = stats:findFirstChild(yPoints1) -
			StatToIncrease.Value  = StatToIncrease.Value +amount1 
			wait(waittime) 
				print(":Script executed successfully!") 
		end

	end

	ting = 0 --remove debounce
	end

end

script.Parent.Touched:connect(OnTouch)

That gives you the point if you stand on it but i want it so when you shoot the button (With a projectile) you get the point, Not when you stand on it??

4 comments

0

(Stand on a button)

0

Describw the problem in more depth please because how you explainwd seems to be just a variable problem.

0

Well there is a button and when you stand on it, it gives you points (Thats what this script does) but i need it so when you shoot the button with a gun or laser etc i don't mind (And not stand on it) It gives you the point. This script means when you stand on the button it gives you a point but i want it so when you shoot the button it gives you the point.

0

Just add a touched event to the projectiles script to check if it touched the button

1 answer

(Forgive me if I misunderstood your question. It's worded pretty badly) Add this to the top of the function:

if Touched.Name ~= "Bullet" then return end

Change "Bullet" to the name of whatever you want to trigger the button If you want more than one kind of projectile then make it if Touched.Name ~= "Bullet" or Touched.Name ~= "Bullet2" then return end

From the looks of your script, the bullet would need to be in the player's character.

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