[~Solved] Does a script run from StarterPlayerScripts? Read desc

I have been trying to make this code that checks if a value has changed, and then returns this new value to the server, but I don’t get any output and nothing seem to change.

After this question has been answered, I’ll go further into details :slight_smile:


Thanks in regards,
@Dev_Mathe (me)

Is it ok if I see the part of the script you’re talking about?

Of course! Here is the entire script lol

print("-- Player Event Has Started --")
warn("-- Player Event Has Started --")

local Player = script.Parent.Parent
local PlayerCoins = Player:WaitForChild("leaderstats"):WaitForChild("Coins") -- the players coins
local EventCoins = game:GetService("DataStoreService"):GetOrderedDataStore(game:GetService("ReplicatedStorage"):WaitForChild("EventDataStoreName")) -- gets data from data store
local success,Data = pcall(function()
	return EventCoins:GetAsync(Player.UserId)
end)
local Eventcoins = Data
if EventCoins == nil then
	EventCoins = 0
end

---


OldValue = PlayerCoins.Value -- Player's current coins

PlayerCoins.Changed:Connect(function(NewVal)
	print("connected to Changed event")
	local Difference = NewVal - OldValue
	print(Difference)
	OldValue = NewVal
end)

It’s a work in progress. Here is the location:
image

add a :WaitForChild(), playerscripts load when the client enters the game and that can be before workspace loads so you should wait for the part

also scripts can’t run from playerscripts, only LocalScripts are accepted there.

2 Likes

Oh. Then how would I check if a player’s value has changed, and change something server-sided?

If your answer is using Remotes, please elaborate.

from characterscripts, Scripts are also accepted from characterscripts

that’s all? But how would I get the localplayer then?

game.Players:FindFirstChild(script.Parent.Name)

Thanks. I’ll try it out. If I need further help, I’ll make sure to keep this conversation alive. I’ll solute this answer in 1-5 minutes.

1 Like

To answer your first question, no, server scripts will not run if placed inside the ‘StarterPlayerScripts’ container, a player’s ‘PlayerScripts’ folder is exclusively for local scripts and by extension module scripts required by local scripts. To fetch the ‘local’ player from a server script placed inside the ‘StarterCharacterScripts’ container you should use the following code.

local Game = game
local Script = script
local Players = Game:GetService("Players")
local Character = Script.Parent
local Player = Players:GetPlayerFromCharacter(Character)
3 Likes

Thank you! This worked better than my current code, as I just tried finding a player with the same name as the character model.