Give player sword if time is whats expected

Hey Devforum! I want to make a player get a sword automatically if they have enough time. So for example if player chareou just got 500 time then automatically reward them with a sword, I already have a datastore and all that. I have no idea how to actually implement this without having lag issues. I’ve tried :RenderStepped to check if they have the wanted time. Whats happening now is that when a player clicks a button it gives them the sword (if they have time) and then saves. I’m using the ProfileService module made by loleris and a Remote Event. My main issue is that ProfileService can only be called from a serverscript. Also, there is multiple swords.

Remote Event

local remote = game:GetService("ReplicatedStorage").OnRequest

remote.OnServerEvent:Connect(function(client, request)
	local inventory_folder = inventories[client.Name]
	local tool = tools[request]
	if inventory_folder:FindFirstChild(tool.Name) then

	else
		local profile = ProfileCache[client]
		if profile ~= nil then 
			if tool:GetAttribute("TypeOfRequirement") == "Time" then
				if profile.Data.Time > tool:GetAttribute("Requirement") then
					tool:Clone().Parent = client.Backpack
					tool:Clone().Parent = inventory_folder	
				end
			else
				if tool:GetAttribute("TypeOfRequirement") == "Kills" then
					if profile.Data.Time > tool:GetAttribute("Requirement") then
						tool:Clone().Parent = client.Backpack
						tool:Clone().Parent = inventory_folder	
					end
				end
			end
		end
	end
end)


wait(7)

If anyone has any idea how to script this then lmk.

1 Like

Ok, so basically if the time is a value instance, then do this in a local script.

NumberValue.Changed:Connect(function()
    if NumberValue.Value == 500 or NumberValue > 500 then
        --remote event fire to reward the sword and save the datastore
    end
end)

If this is not what you’re looking for, sorry because I’m a bit too tired to read both of those scripts right now. Just reply and I’ll come up with something. Good luck!

2 Likes

The thing is that I can’t change the value from a localscript. Save your player data with ProfileService! (DataStore Module)

you don’t need to change the value, you only need to detect it