I tried to make another dropper script where if yo have enough coins then the DropHandler script activates
This is a localscript
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats.Coins.Value >= 5 then
game.ServerScriptService.DropHandler.Enabled = true
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 5
end
end)
This is the script inside serverscriptservice:
local ReplicatedStorage = game.ReplicatedStorage
local Ball = ReplicatedStorage:WaitForChild('Balls')
local DropperPart = workspace:WaitForChild('Dropper')
local NewBall = Ball:Clone()
NewBall.Parent = DropperPart
NewBall.CFrame = DropperPart.CFrame
The client(the code running inside a LocalScript) can’t see what the server sees(for example a script in ServerScriptService) unless it’s replicated to them(which doesn’t). As told in the old topic, for issues like this you must use RemoteEvents to communicate between the Client-Server Model:
--LocalScript
local remote = game.ReplicatedStorage:WaitForChild("DropperRemote")
script.Parent.MouseButton1Click:Connect(function()
remote:FireServer()
end)
--Server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = Instance.new("RemoteEvent", ReplicatedStorage)
remote.Name = "DropperRemote"
local Ball = ReplicatedStorage:WaitForChild("Balls")
local DropperPart = workspace:WaitForChild("Dropper")
remote.OnServerEvent:Connect(function(player)
local Coins = player.leaderstats.Coins
--making the check on the server, so exploiters can't bypass it
if Coins.Value >= 5 then
Coins.Value -= 5
local NewBall = Ball:Clone()
NewBall.Parent = DropperPart
NewBall.CFrame = DropperPart.CFrame
end
end)