I am making a script where if you are seated you get money.
Localscript:
local character = script.Parent
print(character)
local humanoid = character:WaitForChild("Humanoid")
local repStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = repStorage:WaitForChild("GiveThatCashBaby")
function onSeated(isSeated, seat)
if isSeated then
print('player sat down')
RemoteEvent:FireServer()
else
print("I'm not sitting on anything")
end
end
humanoid.Seated:Connect(onSeated)
Server Script
local repStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = repStorage:WaitForChild("GiveThatCashBaby")
local function GiveMoney()
print('Giving Money')
while true do
wait(10)
game.Players.LocalPlayer.leaderstats.Balance = game.Players.LocalPlayer.leaderstats.Balance + 100
print('gave 100')
end
end
RemoteEvent.OnServerEvent:Connect(GiveMoney)
local repStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = repStorage:WaitForChild("GiveThatCashBaby")
local function GiveMoney(player)
player.leaderstats.Balance.Value += 100
end
RemoteEvent.OnServerEvent:Connect(GiveMoney)
You were trying to use “game.Players.LocalPlayer” in a server script (it isn’t defined in server scripts), you were also trying to add 100 to the IntValue instance itself as opposed to the value stored inside the IntValue, you can access the value by appending .Value at the end & finally whenever the client fires the server by calling FireServer() through a RemoteEvent instance the player object pertaining to that particular client is automatically passed as an argument to any callback connected to the corresponding OnServerEvent event listener.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local repStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = repStorage:WaitForChild("GiveThatCashBaby")
function onSeated(isSeated, seat)
if isSeated then
print('player sat down')
RemoteEvent:FireServer()
else
print("I'm not sitting on anything")
end
end
humanoid.Seated:Connect(onSeated)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local repStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = repStorage:WaitForChild("RemoteEvent")
local isInSeat = false
function onSeated(isSeated, seat)
if isSeated then
isInSeat = true
task.spawn(function()
while isInSeat do
RemoteEvent:FireServer()
task.wait(15)
end
end)
else
isInSeat = false
end
end
humanoid.Seated:Connect(onSeated)