Yes, but make sure the player is defined. In that example, I just put LocalPlayer as a placeholder. Replace it with whatever the player instance is.
i put in game.players for the local players and now i have a yellow error Infinite yield possible on 'Players:WaitForChild(“leaderstats”)
I meant the actual player that has the stats:
can you show me how i would put this in code
i put mine in code like this
local stats = game.Players.Guest_player1689:WaitForChild("leaderstats")
Well, assuming you’re handling this on the server, and it’s inside your sell bindable event connection, you’d do this:
ReplicatedStorage.BindableEvents.Sell.OnServerEvent:Connect(function(player)
local stats = player:WaitForChild("leaderstats")
local Cash = stats:WaitForChild("Cash")
Cash.Value += player.leaderstats.Power.Value*2 -- Simplified with +=
stats.Power.Value = 0
end)
does this go in the begging or
end of my code?
I’m not sure what you mean by that. Connections to events can go anywhere, really.
Make sure you switch out the .Event for .OnServerEvent!
make it:
ReplicatedStorage.BindableEvents.Sell.OnServerEvent:Connect(function(player)
if player ~= nil then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + player.leaderstats.Power.Value*2
player.leaderstats.Power.Value = 0
end
end)
it wouldnt be .OnClientEvent,
it’s a server script.
You’re right, I just mixed them up. They’ve been edited out
still getting a error after replacing server event with on server event here is the error now WaitForChild is not a valid member of RBXScriptSignal
what line of code was the error on?
local stats = game.Players.PlayerAdded:WaitForChild("leaderstats")
that is in a different script. could you post the script that was in?
this is the script i clicked on the error and this is where it brought me
heres the whole script
local stats = game.Players.PlayerAdded:WaitForChild("leaderstats")
local Cash = stats:WaitForChild("Cash")
local ReplicatedStorage = game.ReplicatedStorage
ReplicatedStorage.RemoteEvents.Power.OnServerEvent:Connect(function(player, valueFolder)
if player.Debounce.Value == false then
player.leaderstats.Power.Value = player.leaderstats.Power.Value + valueFolder.Power.Value*(player.leaderstats.Rebirths.Value + 1)
player.Debounce.Value = true
wait(valueFolder.cooldown.Value)
player.Debounce.Value = false
end
end)
ReplicatedStorage.BindableEvents.Sell.OnServerEvent:Connect(function(player)
if player ~= nil then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + player.leaderstats.Power.Value*2
player.leaderstats.Power.Value = 0
end
end)
remove the first 2 lines of code, as you dont use them
You need to put the first 2 lines inside the Bindable event connection. For example:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.BindableEvents.Sell.OnServerEvent:Connect(function(player)
if player ~= nil then
local stats = player:WaitForChild("leaderstats")
local Cash = stats:WaitForChild("Cash")
Cash.Value += stats.Power.Value*2
stats.Power.Value = 0
end
end)
those 2 lines arent used… so he doesnt need them
and that will fix the script
PlayerAdded is an event and not an instance, so calling WaitForChild on it is going to produce an error.