I have been trying to figure out what was wrong with my script, but it looked pretty accurate. What my script does, is when a person clicks on the button in a GUI, it should trigger a server script through a local script and RemoteEvent, check their stats, and give them an item. The strange thing is that it works in studio and not in a normal server. It also displays no errors. I would be grateful if anyone could help me in this situation.
Screenshot of the explorer hierarchy: https://gyazo.com/baf47ca163e01e0e0e7f4dd82fc8882b
Local Script:
local plr = game.Players.LocalPlayer
local stats = plr:WaitForChild("leaderstats")
local rep = stats:WaitForChild("Reputation")
local cash = stats:WaitForChild("Cash")
local button = script.Parent
local shop = button.Parent.Parent
local title = shop:WaitForChild("Title")
local rs = game:GetService("ReplicatedStorage")
local event = button:WaitForChild("HealthSyringe") --RemoteEvent
local buysound = script:WaitForChild("Purchase")
repneeded = 0
cashneeded = 30
button.MouseButton1Click:Connect(function()
if rep.Value >= repneeded then
if cash.Value >= cashneeded then
event:FireServer() --firing the RemoteEvent
buysound:Play()
button.Text = "PURCHASED!"
wait(1.5)
button.Text = "PURCHASE-$30"
else
button.BackgroundColor3 = Color3.new(171, 0, 0)
button.Text = "NOT ENOUGH CASH"
wait(3)
button.BackgroundColor3 = Color3.new(0, 0, 127)
button.Text = "PURCHASE-$30"
end
else
button.BackgroundColor3 = Color3.new(171, 0, 0)
button.Text = "NOT ENOUGH REPUTATION"
wait(3)
button.BackgroundColor3 = Color3.new(0, 0, 127)
button.Text = "PURCHASE-$30"
end
end)
This server script doesn't even run at all because the RemoteEvent isn't fired for some reason:
local health = script.Parent:WaitForChild("HealthSyringe") --RemoteEvent
local rs = game:GetService("ReplicatedStorage")
local weapons = rs:WaitForChild("Weapons")
local items = weapons:WaitForChild("Items")
health.OnServerEvent:Connect(function(plr) --receiving the RemoteEvent request
local stats = plr:FindFirstChild("leaderstats")
local cash = stats:FindFirstChild("Cash")
cash.Value = cash.Value - 30
local backpack = plr:FindFirstChild("Backpack")
items["Health Syringe"]:Clone().Parent = backpack
end)

3 comments
You need the remote event and script in the workspace or serverscript scrvice the remote event can also be in the replicated storage
Thanks, it worked!
no problem