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

Script not giving tool when firing Remote Event?

Hi, I am making a script where when you click this button, it fires a remote event to the server to see if they have a value in a folder and if they don't, then the server gives them the tool. The problem is that it doesn't work when giving the tool, nor it takes my money away.

-- Local Script

local confirm = script.Parent.ConfirmFrame.Confirm
local No = script.Parent.ConfirmFrame.No
local DYW = script.Parent.ConfirmFrame.DoYouWish
local ItemVal = script.Parent.Background.ItemNameVal
local RepStorage = game.ReplicatedStorage
local SwordsFol = RepStorage.RemoteEvents.SwordRemotes
local RustyEvent = SwordsFol:WaitForChild("Rusty")
local IronEvent = SwordsFol:WaitForChild("Iron")
local SteelEvent = SwordsFol:WaitForChild("Steel")
local GoldenEvent = SwordsFol:WaitForChild("Golden")
local GalaxyEvent = SwordsFol:WaitForChild("Galaxy")
local GodlyEvent = SwordsFol:WaitForChild("Godly")
local ConFrame = script.Parent.ConfirmFrame

confirm.MouseButton1Click:Connect(function()

	if DYW.Text == "Do you Wish to Buy the <i> Rusty Sword for Free </i>?" and ItemVal.Value == "Rusty Sword" then

		RustyEvent:FireServer()

		ConFrame:TweenPosition(
			UDim2.new(2, 0,0.176, 0),
			"In",
			"Quad",
			.7,
			false,
			nil
		)
	end
	if DYW.Text == "Do you Wish to Buy the <i> Iron Sword for 250 Gold </i>?" and ItemVal.Value == "Iron Sword" then
		ConFrame:TweenPosition(
			UDim2.new(2, 0,0.176, 0),
			"In",
			"Quad",
			.7,
			false,
			nil
		)
		
		IronEvent:FireServer()
	end
	if DYW.Text == "Do you Wish to Buy the <i> Steel Sword for 600 Gold </i>?" and ItemVal.Value == "Steel Sword" then
		ConFrame:TweenPosition(
			UDim2.new(2, 0,0.176, 0),
			"In",
			"Quad",
			.7,
			false,
			nil
		)
		SteelEvent:FireServer()
	end
	if DYW.Text == "Do you Wish to Buy the <i> Golden Sword for 900 Gold </i>?" and ItemVal.Value == "Golden Sword" then
		ConFrame:TweenPosition(
			UDim2.new(2, 0,0.176, 0),
			"In",
			"Quad",
			.7,
			false,
			nil
		)
		GoldenEvent:FireServer()
	end
	if DYW.Text == "Do you Wish to Buy the <i> Galaxy Sword for 1,200 Gold </i>?" and ItemVal.Value == "Galaxy Sword" then
		ConFrame:TweenPosition(
			UDim2.new(2, 0,0.176, 0),
			"In",
			"Quad",
			.7,
			false,
			nil
		)
		GalaxyEvent:FireServer()
	end
	if DYW.Text == "Do you Wish to Buy the <i> Godly Sword for 1,500 Gold </i>?" and ItemVal.Value == "Godly Sword" then
		ConFrame:TweenPosition(
			UDim2.new(2, 0,0.176, 0),
			"In",
			"Quad",
			.7,
			false,
			nil
		)
		GodlyEvent:FireServer()
	end
end)

-- Server Script ( Keep in mind I didn't finish script the rest of the swords )

local RepStorage = game.ReplicatedStorage
local SwordsFol = RepStorage.Swords
local SwordsRemotes = RepStorage.RemoteEvents.SwordRemotes
local RustyEvent = SwordsFol:WaitForChild("Rusty", 15)
local IronEvent = SwordsFol:WaitForChild("Iron", 15)
local SteelEvent = SwordsFol:WaitForChild("Steel", 15)
local GoldenEvent = SwordsFol:WaitForChild("Golden", 15)
local GalaxyEvent = SwordsFol:WaitForChild("Galaxy", 15)
local GodlyEvent = SwordsFol:WaitForChild("Godly", 15)

RustyEvent.OnServerEvent:Connect(function(plr)
	if plr.leaderstats.Gold.Value >= 0 and plr.leaderstats.Gold:IsA("IntValue") then
		local Sword = game.ReplicatedStorage:WaitForChild("Swords"):FindFirstChild("RustySword")
		local char = plr.Character
		local Gold = plr.leaderstats.Gold
		local EqSword = plr:WaitForChild("EqSwordFol")
		local Cost = Sword:GetAttribute("Cost")
		-- Variable's

		local function checkFol()
			for _, sword in pairs(SwordsFol:GetChildren()) do
				for _, v in pairs(EqSword:GetChildren()) do
					if EqSword:FindFirstChild(sword.Name) then
						return true
					else
						return false
					end
				end
			end
		end

		local function checkForsword()
			if char:FindFirstChild("RustySword") then
				return true
			else
				return false
			end
		end

		local hasHaloOrNot = checkForsword()
		local hHON = checkFol()

		if Gold.Value >= Cost and not hasHaloOrNot and not hHON then
			local ClonedSword = Sword:Clone()
			for _, v in pairs(SwordsFol:GetChildren()) do
				Gold.Value = Gold.Value - Cost
				if not plr.EqSwordFol:FindFirstChild(v.Name) and ClonedSword.Parent ~= char and plr.EqSwordFol:GetChildren().Name ~= v.Name then
					local NormalSword = Instance.new("BoolValue", plr:FindFirstChild("EqSwordFol"))
					NormalSword.Name = "RustySword"

					local HasSwordNow = Instance.new("BoolValue")
					HasSwordNow.Name = "RustySword"
					HasSwordNow.Parent = plr.HasSwordsFol

					ClonedSword.Parent = char

					break
				end
			end
		end
	end
end)

IronEvent.OnServerEvent:Connect(function(plr)
	if plr.leaderstats.Gold.Value >= 250 and plr.leaderstats.Gold:IsA("IntValue") then
		local Sword = game.ReplicatedStorage:WaitForChild("Swords"):FindFirstChild("IronSword")
		local char = plr.Character
		local Gold = plr.leaderstats.Gold
		local EqSword = plr:WaitForChild("EqSwordFol")
		local Cost = Sword:GetAttribute("Cost")
		-- Variable's

		local function checkFol()
			for _, sword in pairs(SwordsFol:GetChildren()) do
				for _, v in pairs(EqSword:GetChildren()) do
					if EqSword:FindFirstChild(sword.Name) then
						return true
					else
						return false
					end
				end
			end
		end

		local function checkForsword()
			if char:FindFirstChild("IronSword") then
				return true
			else
				return false
			end
		end

		local hasHaloOrNot = checkForsword()
		local hHON = checkFol()

		if Gold.Value >= Cost and not hasHaloOrNot and not hHON then
			local ClonedSword = Sword:Clone()
			for _, v in pairs(SwordsFol:GetChildren()) do
				Gold.Value = Gold.Value - Cost
				if not plr.EqSwordFol:FindFirstChild(v.Name) and ClonedSword.Parent ~= char and plr.EqSwordFol:GetChildren().Name ~= v.Name then
					local NormalSword = Instance.new("BoolValue", plr:FindFirstChild("EqSwordFol"))
					NormalSword.Name = "IronSword"

					local HasSwordNow = Instance.new("BoolValue")
					HasSwordNow.Name = "IronSword"
					HasSwordNow.Parent = plr.HasSwordsFol

					ClonedSword.Parent = char

					break
				end
			end
		end
	end
end)

If you have a solution, please comment below!

1 comment

0

I bet 89% of the time, nobody's gonna read the hole script.

1 answer

Your issue is that you use plr, when in all the remote events you didn’t pass anything through the function. To simply fix this, you need to put “player” in the 1st argument.

EventNameHere:FireServer(player)

Also, change “plr” in the server script to player.

13 comments

0

No. This is false. You can name variables as you please.

0

No, you don't need to pass in the player when firing to the server, that only happens when firing to the client.

0

But thank you for commenting something!

0

But thank you for commenting something!

0

But thank you for commenting something!

0

But thank you for commenting something!

0

But thank you for commenting something!

0

But thank you for commenting something!

0

But thank you for commenting something!

0

But thank you for commenting something!

0

But thank you for commenting something!

0

But thank you for commenting something!

0

But thank you for commenting something!

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