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

When I shoot the noob why doesn't it give me 100 bux?

Here is the local script in StarterPack:

local mouse = game.Players.LocalPlayer:GetMouse()
local int = Instance.new("IntValue")
int = false
local player = game.Players.LocalPlayer
script.Parent.Activated:Connect(function(Target)
    print(mouse.Target.Parent)
if mouse.Target.Parent == "Noob" then
	int = true
end
if int == true then
	game.ReplicatedStorage.RemoteEvent:FireServer()
end
end)

Here is the script in ServerScriptStorage:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
        player:WaitForChild("leaderstats").Bux.Value = player:WaitForChild("leaderstats").Bux.Value + 100
end)

And here are the leaderstats:

game.Players.PlayerAdded:Connect(function(plr)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = plr
	
	local Bux = Instance.new("IntValue")
	Bux.Parent = stats
	Bux.Name = "Bux"
	Bux.Value = 0
end)

1 answer

✓ Accepted answer

Hello, bluemountainlion!

The below script is just like yours, just a little different. The explanation I put should be enough in the script.

Local Script

local PlayerService = game:GetService("Players")

local Client = PlayerService.LocalPlayer
local ClientMouse = Client:GetMouse()

local IsEquipped = false

local Tool = script.Parent

Tool.Equipped:Connect(function()
	if not IsEquipped then -- a little var to tell if the tool is equipped
		IsEquipped = true
		
		ClientMouse.Button1Down:Connect(function() -- Fires when the player left clicks
			if IsEquipped then
				local MouseTarget = ClientMouse.Target.Parent or ClientMouse.Target.Parent.Parent
				
				if MouseTarget.Name == "Noob" then -- if the Target name is Noob then it fires the server
					game.ReplicatedStorage.RemoteEvent:FireServer()
				end
			end
		end)
	end
end)

Tool.Unequipped:Connect(function()
	if IsEquipped then
		IsEquipped = false -- makes it false when u unequip
	end
end)

1 comment

0

Thanks!

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