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

Why does weapon change between a localscript and a serverscript?

So, I am making a shop and that when you press the button in a gui, it sends a remote event to a server with the player, the character, and the weapon the player wants to buy. However, in the local script, weapon = GoldSword which is what I want it to but when it goes to the server script it equals the player. Why is this?

The localscript

local plr = game.Players.LocalPlayer
local char = plr.Character
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Purchase = ReplicatedStorage:WaitForChild("PurchaseWeapon")
local Weapon = script.Parent.Tool.Value




function leftClick()
	print(Weapon)
	game.ReplicatedStorage:FindFirstChild("PurchaseWeapon"):FireServer(char, plr, Weapon)
end

function onTouchTap()
	game.ReplicatedStorage:FindFirstChild("PurchaseWeapon"):FireServer(char, plr, Weapon)
end

script.Parent.MouseButton1Click:Connect(leftClick)
script.Parent.TouchTap:Connect(onTouchTap)

Serverscript

game.ReplicatedStorage.PurchaseWeapon.OnServerEvent:Connect(function(plr,char,Weapon)
	local Cost = Weapon.Price.Value

	if Cost > plr.Gold.Value or plr.Backpack:FindFirstChild(Weapon) or char:FindFirstChild(Weapon) then
		plr.Gold.Value = plr.Gold.Value
	else
		plr.Gold.Value = plr.Gold.Value - Cost
		Weapon:Clone().Parent = plr.Backpack
	end
end)

1 comment

1 answer

✓ Accepted answer

Correct me if I'm wrong, but I believe that the "Player" value is automatically sent if you dont add it, which means right now, your doing something along the lines of

FireServer(player, char, plr, Weapon)

So what you probably should do is something like this inside the script instead

FireServer(char, Weapon)

and then you send 3 values. Player, Character, and Weapon

and then in the server script, what should work is

OnServerEvent:Connect(function(plr,char,Weapon)

which is what you wrote, I'm just trying to make sure I'm understandable.

Sorry in advance if I'm incorrect!

That's all, have a nice day!

2 comments

0

Thanks a bunch

0

i think im late on this response, but your welcome!!

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