For first, you can't remove value with variable, only update the variable not the value in object,
Example:
local myValue = workspace.myValue.Value
myValue = myValue - 1
Its simple to fix, only use .Value on remove example:
local myValue = workspace.myValue
myValue.Value = myValue.Value - 1
(for see more of the .Value see the answer of Incapaxian, you can understand more: Incapaxian Answer)
Fixed scripts:
On your client, only use game.Players.LocalPlayer, also for fire RemoteEvent you dont need to send player, the first argument of the RemoteEvent is the PLayer
local event = game.ReplicatedStorage.RemoteEvent
local price = script.Parent.Parent.Price
local tools = game:GetService("ReplicatedStorage"):WaitForChild("Tools")
local tool = tools:FindFirstChild(script.Parent.Parent.ItemName.Value)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
event:FireServer(price.Value, tool.Name)
end)
In your event script put this:
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
event.OnServerEvent:Connect(function(plr,price,toolName)
local stats = plr:WaitForChild("leaderstats")
local Point = stats:WaitForChild("Point")
local tool = game:GetService("ReplicatedStorage"):WaitForChild("Tools"):FindFirstChild(toolName)
print(Point.Value)
if Point.Value >= price then
Point.Value = Point.Value - price
else
print("You dont have money.")
end
print("Done!")
end)
Well this remote event is not protected so I would recommend you create the price inside the tools and check if the player has the money on the server.
For use protected RemoteEvents only put the Price(with IntValue named as Price) inside the tool and only send the name of tool to server
(Client)
local event = game.ReplicatedStorage.RemoteEvent
local tools = game:GetService("ReplicatedStorage"):WaitForChild("Tools")
local tool = tools:FindFirstChild(script.Parent.Parent.ItemName.Value)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
event:FireServer(tool.Name)
end)
(Server)
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
event.OnServerEvent:Connect(function(plr,toolName)
local stats = plr:WaitForChild("leaderstats")
local Point = stats:WaitForChild("Point")
local tool = game:GetService("ReplicatedStorage"):WaitForChild("Tools"):FindFirstChild(toolName)
local price = tool:FindFirstChild("Price")
if price then
print(Point.Value)
if Point.Value >= price.Value then
Point.Value = Point.Value - price
else
print("You dont have money.")
end
print("Done!")
else
print("Price not found")
end
end)
Hope it helped :D
Wiki pages
RemoteEvents/Functions
Errors? tell-me on comments.
1 comment
i posted a answer for fix all problems.